c++ programming

Go To StackoverFlow.com

0

I am writing a program that calculates and prints parking charges i am using get.line for the user to enter, how do i use "find" to separate the line?

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
using namespace std;
int main ()
{
string enter_date;
string enter_time;
string exit_date;
string exit_time;
int calculatecharge;
int num;

cout << "Please enter the date and time the car is entering "<< endl
<< "the parking garage in the following format: YY/MM/DD hh:mm"<< endl;
getline (cin,enter_date);
getline (cin,enter_time);
cout<< "Please enter the date and time the car is exiting "<< endl
<< "the parking garage in the following format: YY/MM/DD hh:mm"<< endl;
getline (cin,exit_date);
getline (cin,exit_time);

find(' ')


cout<<"Parking fee due: "<< num << endl;
return 0;
}
2012-04-04 03:42
by user1311854
I fixed the format for you; fix your spelling and punctuation, phrase your question more carefully, show us that you spent more than ten seconds posting this question, and chances are you'll get good help here - Beta 2012-04-04 03:46
With getline you will get a line of inputs, so if the user enter, "2012/4/3 11:59", you enter_date string will contain that line. If you expect YY/MM/DD format then why not just read in expecting that. For example, std::cin >> yearStr >> dummyChar >> monthStr >> dummyChar >> dayStr - dchhetri 2012-04-04 03:49
I have only been working on C++ for a month. I am still trying to learn all the functions and style for programming and I am not able to get help from my instructor (He is not helping) I am learning this on my own and have to write the program in the format that he wants. Thank you for helping me with my program - user1311854 2012-04-04 04:18
I am still having trouble with my program I have added if (str.find (' ') != string::npos) to break up the line, but I am not sure if I did it right. Could someone please explain how to use find and what the arguments should be - user1311854 2012-04-04 04:53
I am not sure if there is another way to write it without using getline because I am having a hard time understanding how to make it work. I really appreciate the help. My assignment for class is...A parking garage charges a $2.00 min fee to park for up to 3hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The max charge for any given 24-hour period is $10.00. Cars parked for longer than 24hours will pay $8.00 per day. Write a program that calculates and prints the parking charges. Both inputs are in the format of YY/MM/DD hh:mm - user1311854 2012-04-05 04:47


0

If you are using getline() twice, try the below code.

getline (cin, enter_date, ' ');
getline (cin, enter_time);
2012-04-04 08:43
by user519986
Ads