我正在嘗試編寫一個程序來計算和顯示高於60英寸的學生的高度。例如:我需要它來計算並顯示高於60英寸的學生人數並顯示他們各自的高度。我不確定如何存儲單獨的值並顯示它們的高度。我已經掌握了計算高於60英寸的學生人數的計劃,但我需要幫助來顯示他們的具體身高。需要幫助顯示循環/數組程序中的值C++
#include <iostream>
using namespace std;
int main()
{
double count60 = 0.0;
double height[10];
for (int x = 0; x < 10; x = x + 1)
{
height[x] = 0.0;
}
cout << "You are asked to enter heights of 10 students. "<< endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << "Enter height of a student: ";
cin >> height[x];
if (height[x] > 60)
{
count60 = count60 + 1;
}
}
cout << "The number of students taller than 60 inches: "<< count60 << endl;
cout << "The heights of these students are: "
system("pause");
return 0;
}
你應該考慮寫增量爲 「++ X」,而不是 「X = X + 1」。這是更好的風格。另外,count60應該是一個整數,而不是雙倍。 – Muscles