0

我必须做一个时间跟踪程序。目标是让用户被提示输入日期、时间和任务描述,然后它将它们全部打印在列中(尚未编写列代码),但是我遇到了很多错误,我没有不知道解决这个问题的最佳方法。我需要几个小时才能在最后加起来。这是我的代码:

#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;
}

任何人都可以说明情况吗?

4

1 回答 1

0

首先,您有一些终端编码问题。编译器实际上打印的不是 â。有关如何解决,请参见此处:https ://superuser.com/questions/264089/strange-characters-in-terminal-during-compile-error 快速总结:尝试使用LC_ALL=en_US前缀运行编译器,例如

 LC_ALL=en_US g++ shuffle_string.cpp

如果您显示的代码与您编译的代码不完全对齐(关于行号),则编译错误可能来自类型std::前面的缺失string(应该是std::string) - 和 也是cout如此cin

另外,你应该

#include <string>

不是string.h

于 2013-11-08T12:11:30.177 回答