#include <iostream>
using namespace std;
int main()
{
double sixty = 0.0;
double fiftyfive = 0.0;
double height[10];
double tallest = 0.0;
double shortest = 0.0;
double average = 0.0;
double total = 0.0;
for (int x = 0; x < 10; x = x + 1)
{
height[x] = 0.0;
}
cout << "Please enter the heights of ten students. "<< endl;
for (int x = 0; x < 10; x = x + 1)
{
cout << "Enter height of a student: ";
cin >> height[x];
}
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] > 60)
{
sixty = sixty + 1;
}
}
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] < 55)
{
fiftyfive = fiftyfive + 1;
}
}
cout << "The number of students over 60 inches in height: " << sixty << endl;
cout << "The number of students under 55 inches in height: " << fiftyfive << endl;
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] > tallest)
{
tallest = height[x];
}
}
cout << "The tallest student is: " << tallest << endl;
for (int x = 0; x < 10; x = x + 1)
{
if (height[x] < shortest)
{
shortest = height[x];
}
}
cout << "The shortest student is: " << shortest << endl;
for (int x = 0; x < 10; x = x + 1)
{
total = total + height[x];
}
average = total/10;
cout << "The average student height is: " << average << endl;
system("pause");
return 0;
}
在上面,我要吐了學生的#超過60英寸,學生在55in的#,平均高度,最高高度,並在最短的高度。C++最小的序列號不顯示
一切工作正常,除了最短的高度。我爲這部分代碼返回零輸出。
這是簡單的代碼,所以我想這是一個簡單的問題,我忽略了。任何輸入讚賞。
任何原因,你在使用'X = X + 1'而不是說,'+ + x'? – tadman 2013-04-23 19:24:53
任何原因***所有這些限制都不計算在陣列的*相同*單程中。 – WhozCraig 2013-04-23 19:25:52
使用x = x + 1,因爲這就是本章所有例子中的用法(這是C++類的介紹)。所以我儘量讓它保持在課程目前的狀態。 – Brocktoon 2013-04-23 19:26:34