我只在C++上工作了大約一個月。我不是很瞭解它是如何工作的,但是我需要爲學校編寫一個程序。我用了一個void函數,它似乎工作到目前爲止,但我不知道該怎麼辦下一步我在第44行丟失,我不知道如何使它工作,有沒有辦法從一個值某些字符串?如果這個值在兩個字符串中,我將如何確定哪個值?這裏是我的任務:如何使用getline和stringstream分析格式化的日期和時間輸入?
停車場收費最低爲2美元停車長達三小時的費用。車庫每小時或每小時額外收費0.50美元,超過三小時。任何給定24小時期限的最高收費爲10美元。將車停放超過24小時的人每天將支付8美元。
編寫一個計算和打印停車費用的程序。您的程序輸入是汽車進入停車庫的日期和時間,以及同一輛汽車離開停車場的日期和時間。兩個輸入是在YY/MM/DD,格式爲HH:MM
這裏是我到目前爲止已經編寫的代碼:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <sstream>
using namespace std;
stringstream ss;
string enter_date;
string enter_time;
string exit_date;
string exit_time;
int calculatecharge;
int num;
int i;
int year;
int month;
int ddmmyyChar;
int dayStr;
string line;
int x;
void atk()
{
getline (cin,line); // This is the line entered by the user
stringstream ss1(line); // Use stringstream to interpret that line
ss >> enter_date >> enter_time;
stringstream ss2(enter_date); // Use stringstream to interpret date
string year, month, day;
getline (ss2, year, '/');
}
int main()
{
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;
atk();
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;
atk();
if (hr - hr < 3)
cout<<"Parking fee due: $2.00" << endl;
您包含的某些頭文件不是必需的。例如,如果您沒有執行文件I/O,則不需要'#include'。 –
bwDraco
2012-09-17 01:56:11