简体   繁体   English

我不知道如何重复整个程序

[英]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: 例如,如果要在用户告诉您输入0 (或更少)的成绩时结束循环,请尝试以下操作:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Domino程序。 我不知道如何将向量拉成空白以将其打印出来 - Dominoes program. I can't figure out how to pull my vector into a void to print it out 无法弄清楚在给定情况下如何在输出中编程 - Can't figure out how to program in outputs for the given situations 我不知道如何使我的程序使用局部变量而不是全局变量 - I can't figure out how to make my program use local variables instead of global variables 输入姓名和身高并显示的程序。 我不知道如何显示列表中最高人的姓名和身高 - Program to input Name and Height and Display it. I can't figure out how to display the name and Height of the tallest person in the list 我不知道如何填充数组 - I can't figure out how to fill an array 我不知道如何打印数组,反过来,我也不知道如何交换数组中的元素 - I can't figure out how to print arrays and in turn, I can't figure out how to swap elements in an array 我不知道我的 C++ 程序有什么问题 - I can't figure out what's wrong with my c++ program 这个简单的c ++程序可以永远运行,我不知道为什么 - This simple c++ program runs forever and I can't figure out why 我的程序在完成后打印错误的东西,我不知道为什么。 C++ - My program is printing the wrong thing after completing, and I can't figure out why. C++ 简单的循环我不知道 - Simple for loop I can't figure out
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM