简体   繁体   中英

I can't figure out how to repeat this whole program

I feel like this is a very simple task but I am just learning so if somebody can show me this is would be greatly appreciates. Can someone show me how to repeat this little program from the beginning. thanks!

I want to repeat all of this:

#include <iostream>
#include <cmath>
#include <string>

using namespace std;
int main()
{
    std::cout<<"Welcome to my grade book!\n";

    int grade_var=0,grade_1=0,sum=0;
    cout<<"Enter the number of grades you have:\t";

    cin>>grade_var;

    for(int i=1;i<=grade_var;i++)
    {
        cout<<endl<<"Enter the "<<i<<" number:\t";
        cin>>grade_1;
        sum=sum+grade_1;
    }
    sum=sum/grade_var;

    cout<<endl<< sum;

    cout<<endl<<"Letter Grade:\n";

    if(sum>=96)
        cout<<"A";
    else
    {
        if(sum>=91)
            cout<<"A-";
        else
        {
            if(sum>=87)
                cout<<"B+";
            {
                if(sum>=83)
                    cout<<"B";
                else
                {
                    if(sum>=80)
                        cout<<"B-";
                    else
                    {
                        if(sum>=77)
                            cout<<"C+";
                        else
                        {
                            if(sum>=73)
                                cout<<"C";
                            else
                            {
                                if(sum>=70)
                                    cout<<"C-";
                                else
                                {
                                    if(sum>=67)
                                        cout<<"D+";
                                    else
                                    {
                                        if(sum>=63)
                                            cout<<"D";
                                        else
                                        {
                                            if(sum>=60)
                                                cout<<"D-";
                                            else
                                                cout<<"F";
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return 0;
}
int main () {
    while(true) {
        //do everything
    }
    return 0;
}

Standard infinite loop stuff.

If you want to end the loop when the user, for example, tells you they have 0 (or fewer) grades to enter, then try this:

int main () {
    while(true) {
        // prompt and get input
        if(grade_var <= 0) {
           break;
        }
        // do stuff when they have grades
    }
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM