/* C Program 4 - Corey Jones - cjtx6362@yahoo.com */
#include <iostream.h> // include system information
int main()
{
int numValues, count;
float sum, num, largest, smallest;
count = 1;
sum = numValues + num;
numValues = 1;
cout << "C Program 4 CSCE 1020.002" << endl
<< "Corey Jones cjtx6362@yahoo.com" << endl << endl;
cout << "Enter a number between 5 and 10: ";
cin >> num;
while (num < 5 || num > 10)
{
cout << "Number invalid, please try again: ";
cin >> num;
}
for(count=1; count<= numValues; count ++)
{
if (count == 1) largest = smallest = num;
else
{
if (smallest > num) smallest = num;
if (largest < num) largest = num;
}
cout << "The sum is " << sum << endl;
cout << "The average is " << sum / numValues << endl;
cout << "The largest is " << largest << endl;
cout << "The smallest is " << smallest << endl;
}
return 0;
}
Our assignment is to create a loop. The user enters a variety of numbers and the computer bugs them to enter it in the range. It also takes the numbers that he enters and display the sum and display the average of the numbers, the smallest and the largest. I can get it to display the largest and smallest. But I can't get it to display my sum or average. I get this wierd e number for both of them. Any ideas to help?
#include <iostream.h> // include system information
int main()
{
int numValues, count;
float sum, num, largest, smallest;
count = 1;
sum = numValues + num;
numValues = 1;
cout << "C Program 4 CSCE 1020.002" << endl
<< "Corey Jones cjtx6362@yahoo.com" << endl << endl;
cout << "Enter a number between 5 and 10: ";
cin >> num;
while (num < 5 || num > 10)
{
cout << "Number invalid, please try again: ";
cin >> num;
}
for(count=1; count<= numValues; count ++)
{
if (count == 1) largest = smallest = num;
else
{
if (smallest > num) smallest = num;
if (largest < num) largest = num;
}
cout << "The sum is " << sum << endl;
cout << "The average is " << sum / numValues << endl;
cout << "The largest is " << largest << endl;
cout << "The smallest is " << smallest << endl;
}
return 0;
}
Our assignment is to create a loop. The user enters a variety of numbers and the computer bugs them to enter it in the range. It also takes the numbers that he enters and display the sum and display the average of the numbers, the smallest and the largest. I can get it to display the largest and smallest. But I can't get it to display my sum or average. I get this wierd e number for both of them. Any ideas to help?