using counter-loop structure, write a program segment to accept the weight of 100 students. the program counts and displays the number of students whose weight is more than 75 kilograms
#include <iostream>
int main()
{
// simple counter-loop example
float weight{ 0 };
int count_people{ 1 };
int count_weight{ 0 };
while (count_people <= 100)
{
std::cout<<"Enter the weight of the " <<count_people<<" students: ";
std::cin >> weight;
if (weight > 75) {
count_weight += 1;
}
count_people += 1;
}
std::cout << "Number of students weighing more than 75 kgn" << count_weight << std::endl;
return 0;
}
Comments
Leave a comment