Hello all, I am having a bit of trouble figuring out the solution to this:
Code:
#include <stdio.h>
#include <stdlib.h>
/*
You are to write a program that will allow a user to enter infinite numbers (greater than zero)
(One number at a time). You must have a way for the user to stop entering values.
Once the user stops, you will immediately display the following:
The lowest number entered is:
The highest number entered is:
The number of values entered is:
The average of the numbers entered is:
*/
main() {
int userNumber=0, sum=0, count=0, highNum=0, lowNum=0, lastNum = 0;
double average;
printf("Enter a number greater than 0: (Enter -1 to stop) \n");
scanf_s("%i", &userNumber);
while (userNumber != -1){
if (userNumber > lowNum && userNumber > highNum)
highNum = userNumber;
count = count + 1;
sum = sum + userNumber;
printf("Enter a number:(-1 to stop)\n");
scanf_s("%i", &userNumber);
}
average = (double)sum / count;
printf("\t The sum is: %i\n", sum);
printf("\t %i numbers were input\n", count);
printf("\t The average is %.2lf\n", average);
printf("The highest number entered was: %i", highNum);
printf("The last number entered was: %i", lastNum);
printf("The lowest number entered was: %i", lowNum);
system("pause");
}
My program outputs everything I need except the lowest number entered. I have been spending a considerable amount of time on this problem to no avail. Please help me out here fellow programmers! This is for a school project due tomorrow. More important than the homework, however, is the fact that I truly want to figure this out. I'm a new programmer but I plan to make this my career so I am extremely hungry for knowledge!! Thanks in advance to you awesome helpers, guru's and mentors