时间跟踪器计划协助

时间:2013-11-08 11:00:33

标签: c++

我必须制作一个时间跟踪程序。目标是提示用户输入日期,输入的小时数和任务描述,然后将它们全部打印在列中(尚未编写列代码),但是我收到很多错误而且我不知道知道解决这个问题的最佳方法。最后我需要几个小时才能完成。这是我的代码:

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

任何人都可以了解情况吗?

1 个答案:

答案 0 :(得分: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) - 同样适用于coutcin

另外,你应该

#include <string>

不是string.h