我需要制作一个程序,它需要6个浮点数,最后我必须在数组中从最小到最大排序它们,然后删除最大和最小数字。C++ for循环接受输入来填充数组
#include <iostream>
using namespace std;
int main(){
bool flag;
float score1, score2, score3, score4, score5, score6;
int size;
float scoresheet [6] = {score1, score2, score3, score4, score5, score6};
cout << "Pleaser enter your score for the gymnast: ";
cin >> score1;
while (cin.fail() || score1 > 10 || score1 < 0)
{
cout << "Invalid score!" << endl;
cout << "Pleaser enter your score for the gymnast: ";
cin >> score1;
}
这是我到目前为止。我知道我需要做一个for循环,但我该怎么做,以便在输入验证后,它会将6个输入分配到它在数组'scoresheet'中的位置?提前致谢。
如果你要单独声明(并使用)'score1','score2'等,为什么还要有一个'scoresheet [6]'? –
带上你的验证循环,把它放在for循环中。使用数组。 –
我认为这是制作数组的正确方法@R_Kapp –