#include <iostream> using namespace std; int main() { double height[10]; int tal
ID: 3539270 • Letter: #
Question
#include <iostream>
using namespace std;
int main()
{
double height[10];
int tall=0;
for(int x=0;x<10;x++)
{
height[x] = 0.0;
}
cout<<"Enter the height of 10 students."<<endl;
for(int x=0; x<10; x++)
{
cout<< "Enter the height of the student: ";
cin>>height[x];
if(height[x]>60)
{
tall++;
}
}
cout<<"Number of students taller than 60 inches: "<<tall<<endl;
}
Modify your program in Program 1 (code above). In addition to count and display the number of students taller than 60 inches, also count and display the number of students shorter than 55 inches.
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
double height[10];
int tall=0;
int small = 0;
for(int x=0;x<10;x++)
{
height[x] = 0.0;
}
cout<<"Enter the height of 10 students."<<endl;
for(int x=0; x<10; x++)
{
cout<< "Enter the height of the student: ";
cin>>height[x];
if(height[x]>60)
{
tall++;
}
else if(height[x]< 55)
{
small++;
}
}
cout<<"Number of students taller than 60 inches: "<<tall<<endl;
cout<<"Number of students shorter than 55 inches: "<<small<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.