finding the smallest, largest,average number do while loop ,pls help

im stuck looking at whats the problem, please help.



#include <iostream>


using namespace std;

int main()
{
float average, largest = 0, smallest = 0;
int count = 1;
int num;

do

{

cout << "Enter three numbers\n\n";
cout << "Enter the first number: ";
cin << num;

cout << "Enter a number: ";
cin << num;

cout << "Enter a number: ";
cin << num;

while (count < 3 )
{
if (count == 1) {
largest = num;
smallest = num;
}
else {
if ( num > largest )
largest = num;
if ( num < smallest )
smallest = num;
}

count++;
}

average = ( sum / (count - 1) );


cout << endl << "The smallest number is " << smallest << endl;
cout << "The largest number is " << largest << endl;
cout << "The average of all numbers is " << average << endl;

system ("pause");


return 0;
}
Last edited on
Your variable num is getting overwritten in subsequent read operations. You need to have different variable names for storing the values of the three different variables.
Topic archived. No new replies allowed.