我必须做一个时间跟踪程序。目标是让用户被提示输入日期、时间和任务描述,然后它将它们全部打印在列中(尚未编写列代码),但是我遇到了很多错误,我没有不知道解决这个问题的最佳方法。我需要几个小时才能在最后加起来。这是我的代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
int hours = 0;
string i;
int j = 0;
string h;
string date;
string task;
int totalHours;
char answer;
while(1) {
cout << "Please enter the date of the task: ";
cin >> i;
cout << "Please enter the number of hours worked: ";
cin >> j;
cout << "Please enter the description of the task completed: ";
cin >> h;
if(j != 0 && i != 0 && h != 0)
{
printf("Entry added. ");
while(1){
date = i;
hours = j;
task = h;
totalHours = hours + j; }
else {
break;
} }
cout << "Would you like to enter another task?(y or n): ";
cin >> answer;
if (answer == 'n'){
cout << "Your time is spent like this" << date << " " << hours << " " << task;
cout << "The total number of hours spent is" << totalHours;
}
}
return 0;
}
任何人都可以说明情况吗?