Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
让C++程序多问几遍_C++ - Fatal编程技术网

让C++程序多问几遍

让C++程序多问几遍,c++,C++,有人能帮我吗?我想做一个程序,问我第一个是什么,第二个是什么,第三个是什么?等,我希望它问我,因为我告诉过它很多次。它存储在int noftimes中 #include <iostream> #include <string> using namespace std; int main() { //Get number of grades. int nofgrades = 7; cout << "How many grades do

有人能帮我吗?我想做一个程序,问我第一个是什么,第二个是什么,第三个是什么?等,我希望它问我,因为我告诉过它很多次。它存储在int noftimes中

#include <iostream>
#include <string>
using namespace std;

int main()
{
    //Get number of grades.
    int nofgrades = 7;
    cout << "How many grades do you want to calculate?\n";
    cin >> nofgrades;
    //Get grades.
    cout << "What's the " << (nofgrades - (nofgrades - 1)) << "st grade?\n";
    //Calculate average.

    //Display average.


    return 0;
}

我正在用C++编程。感谢所有帮助。

给你,通过使用for循环,你可以很容易地完成你的要求。阅读更多关于for循环和一般编程原则的内容。查看subreddit侧边栏以获得良好的资源

#include <iostream>
#include <string>
using namespace std;

int main()
{
    //Get number of grades.
    int nofgrades; // Why did you initialize it when you're going to override it anyway?
    cout << "How many grades do you want to calculate?\n";
    cin >> nofgrades;
    //Get grades.
    for (int i = 1; i <= nofgrades; ++i) {
        cout << "What's the " << i << "st grade?\n";
        //Load aditional grades... 
    }
    //Calculate average.

    //Display average.


    return 0;
}

你应该买本好书。你知道什么是循环吗?如果没有,,试着了解这一点,下次再问一个更具体的问题。你想问第一个是什么或第一个是什么吗?这个问题似乎离题了,因为它涉及的主题在任何好的入门书中都有涉及。你需要一些详细的编码来将7654321转换为柒佰陆拾伍万肆仟叁佰贰拾元首先…什么是2st等级?好的,没错,需要一些额外的逻辑,但出于教育目的,循环很重要。谢谢!这就是我想要的哦,是的,我忘了说初始化变量是个很好的练习。是这样吗?编辑:添加了一个?。