有人能帮助我吗?我想制作一个程序,问我“第一个是什么?”,“第二个是什么?”,“第三个是什么?”我希望它能像我告诉它的那样多次问我。它存储在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 ++编程。感谢所有帮助。
答案 0 :(得分:0)
在这里,通过使用for循环,您可以轻松地执行所要求的操作。阅读有关for循环和一般编程原理的更多信息。查看this 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;
}