C++程序读取日期值

发布于 2024-11-19 12:23:40 字数 5028 浏览 2 评论 0原文

这个程序有问题..

收到错误“必须在第116行返回'Int'..

#include <iostream>
#include <fstream>
//#include <stdio>
#include <string>
using namespace std;
/********************************************************************/
/*Function: to validate the score is valid
Parameter: score1 ,score 2, score3
return: true: if 3 score is valid
        false: if at least 1 score is invalid
/********************************************************************/

bool isitavalidset(int score1,int score2,int score3)

{
    bool isvalid = true;
    //check valid score1
    if(score1 < 18 || score1> 100)
    {
        cout<<"Score1 is invalid value\n";
        isvalid = false;
    }
    //check valid score2
    if(score2 < 18 || score2> 100)
    {
        cout<<"Score3 is invalid value\n";
        isvalid = false;
    }
    //check valid score3
    if(score3 < 18 || score3> 100)
    {
        cout<<"Score3 is invalid value\n";
        isvalid = false;
    }

    return isvalid;
}

/********************************************************************/
/*Function: to classify the status of 3 score
Parameter: score1 ,score 2, score3
return: print out the screen
/********************************************************************/
void findpattern(int score1, int score2,int score3)
{
    //stayed in the same
    if((score1 == score2) &&(score2 == score3))
    {
        cout<<"stayed the same\n";
    }//inccreasing
    else if((score1 < score2) && (score2 < score3))
    {
        cout<<"increasing\n";
    }//decreasing
    else if((score1 > score2) &&(score2 > score3))
    {
        cout<<"decreasing\n";
    }//two left or right are the same
    else if((score1 == score2) || (score2 == score3))
    {
        cout<<"two the same\n";
    }//up and down
    else if(score1 > score2)
    {
        cout<<"up and down\n";
    }//down and up
    else if(score1 < score2)
    {
        cout<<"down and up\n";
    }//no case,it is impossible to occur
    else {
        cout<<"this type of value is not classified\n";
    }
}
/********************************************************************/
/*Function: to count 3 score for each group
Parameter: score1 ,score 2, score3
return: print out the screen
/********************************************************************/
void countranges(int score1, int score2, int score3)
{
    int belowpar = 0;
    int atpar = 0;
    int abovepar = 0;
    //we do not care the range, because we has been check the range outside, this number must be valid
    if(score1 < 70) belowpar++;
    else if(score1 == 70) atpar++;
    else if(score1 > 70) abovepar++;
    //we do not care the range, because we has been check the range outside, this number must be valid
    if(score2< 70) belowpar++;
    else if(score2 == 70) atpar++;
    else if(score2 > 70) abovepar++;
    //we do not care the range, because we has been check the range outside, this number must be valid
    if(score3 < 70) belowpar++;
    else if(score3 == 70) atpar++;
    else if(score3 > 70) abovepar++;
    //printing the value here
    cout<<belowpar<<" below par (18-69 range)        " <<atpar<<" at par (exactly 70)         "<<abovepar<<" above par (71-100 range)\n";

}
/********************************************************************/
/*Function: to call the other function
Parameter: score1 ,score 2, score3
return: nothing
/********************************************************************/
void classify(int score1,int score2, int score3)
{
    findpattern(score1,    score2,    score3);
    countranges(score1,    score2,    score3);
}
/********************************************************************/
/*Function: control the input of data and print result
Parameter: score1 ,score 2, score3
return: nothing
/********************************************************************/


// Getting error from this line,,,  error "must return 'Int'
void main(int argc, char* argv[])
{
    int score1,score2,score3;
    int totalgroupgood = 0;
    int totalgroupbad = 0;
    //Input file
    ifstream infile;
    if(argc != 2)
    {
        return;
    }
   //read the file from input
    infile.open (argv[1]);

        while(!infile.eof()) // To get you all the lines.
            {
                //set value to score1,score2,score3
                infile>>score1;
                infile>>score2;
                infile>>score3;

                if(isitavalidset(score1,score2,score3))
                {
                    classify(score1,score2,score3);
                    totalgroupgood++;
                }else{
                    totalgroupbad++;
                }

        }

    infile.close();
    cout<<"Total valid group:"<<totalgroupgood<<"\n";
    cout<<"Total invalid group:"<<totalgroupbad<<"\n";


}

谢谢。

having problem with this program..

getting a error "must return 'Int' in line 116..

#include <iostream>
#include <fstream>
//#include <stdio>
#include <string>
using namespace std;
/********************************************************************/
/*Function: to validate the score is valid
Parameter: score1 ,score 2, score3
return: true: if 3 score is valid
        false: if at least 1 score is invalid
/********************************************************************/

bool isitavalidset(int score1,int score2,int score3)

{
    bool isvalid = true;
    //check valid score1
    if(score1 < 18 || score1> 100)
    {
        cout<<"Score1 is invalid value\n";
        isvalid = false;
    }
    //check valid score2
    if(score2 < 18 || score2> 100)
    {
        cout<<"Score3 is invalid value\n";
        isvalid = false;
    }
    //check valid score3
    if(score3 < 18 || score3> 100)
    {
        cout<<"Score3 is invalid value\n";
        isvalid = false;
    }

    return isvalid;
}

/********************************************************************/
/*Function: to classify the status of 3 score
Parameter: score1 ,score 2, score3
return: print out the screen
/********************************************************************/
void findpattern(int score1, int score2,int score3)
{
    //stayed in the same
    if((score1 == score2) &&(score2 == score3))
    {
        cout<<"stayed the same\n";
    }//inccreasing
    else if((score1 < score2) && (score2 < score3))
    {
        cout<<"increasing\n";
    }//decreasing
    else if((score1 > score2) &&(score2 > score3))
    {
        cout<<"decreasing\n";
    }//two left or right are the same
    else if((score1 == score2) || (score2 == score3))
    {
        cout<<"two the same\n";
    }//up and down
    else if(score1 > score2)
    {
        cout<<"up and down\n";
    }//down and up
    else if(score1 < score2)
    {
        cout<<"down and up\n";
    }//no case,it is impossible to occur
    else {
        cout<<"this type of value is not classified\n";
    }
}
/********************************************************************/
/*Function: to count 3 score for each group
Parameter: score1 ,score 2, score3
return: print out the screen
/********************************************************************/
void countranges(int score1, int score2, int score3)
{
    int belowpar = 0;
    int atpar = 0;
    int abovepar = 0;
    //we do not care the range, because we has been check the range outside, this number must be valid
    if(score1 < 70) belowpar++;
    else if(score1 == 70) atpar++;
    else if(score1 > 70) abovepar++;
    //we do not care the range, because we has been check the range outside, this number must be valid
    if(score2< 70) belowpar++;
    else if(score2 == 70) atpar++;
    else if(score2 > 70) abovepar++;
    //we do not care the range, because we has been check the range outside, this number must be valid
    if(score3 < 70) belowpar++;
    else if(score3 == 70) atpar++;
    else if(score3 > 70) abovepar++;
    //printing the value here
    cout<<belowpar<<" below par (18-69 range)        " <<atpar<<" at par (exactly 70)         "<<abovepar<<" above par (71-100 range)\n";

}
/********************************************************************/
/*Function: to call the other function
Parameter: score1 ,score 2, score3
return: nothing
/********************************************************************/
void classify(int score1,int score2, int score3)
{
    findpattern(score1,    score2,    score3);
    countranges(score1,    score2,    score3);
}
/********************************************************************/
/*Function: control the input of data and print result
Parameter: score1 ,score 2, score3
return: nothing
/********************************************************************/


// Getting error from this line,,,  error "must return 'Int'
void main(int argc, char* argv[])
{
    int score1,score2,score3;
    int totalgroupgood = 0;
    int totalgroupbad = 0;
    //Input file
    ifstream infile;
    if(argc != 2)
    {
        return;
    }
   //read the file from input
    infile.open (argv[1]);

        while(!infile.eof()) // To get you all the lines.
            {
                //set value to score1,score2,score3
                infile>>score1;
                infile>>score2;
                infile>>score3;

                if(isitavalidset(score1,score2,score3))
                {
                    classify(score1,score2,score3);
                    totalgroupgood++;
                }else{
                    totalgroupbad++;
                }

        }

    infile.close();
    cout<<"Total valid group:"<<totalgroupgood<<"\n";
    cout<<"Total invalid group:"<<totalgroupbad<<"\n";


}

thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天气好吗我好吗 2024-11-26 12:23:40
void main(int argc, char* argv[])

不合法;它必须更改为:

int main(int argc, char* argv[])

main() 作为一种特殊情况,您可以选择在最后放置一个return语句,它是可选的。 请参阅此处,来自 Bjarne Stroustrup 页面的链接。简而言之,main() 必须返回 int

void main(int argc, char* argv[])

is not legal; it must be changed to:

int main(int argc, char* argv[])

main() being a special case, you can choose to put a return statement in the end, it's optional. See here, the link from Bjarne Stroustrup's page. In nutshell main() must return int.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文