Hey all I'm new here and I really appreciate this resource and all your help.
So here goes,...
I am in a beginners c programming class and I have been presented with the following problem:
"Write a program that finds the largest in a series of numbers enterd by the user. The program must prompt the user to enter numbers one by one. When user enters 0 or a negative number, the program terminates and must display the largest nonnegative number entered."
Okay so here's my code so far:
insert
Code:
#include <stdio.h>
int main(void)
{
float number, highestnumber;
printf("Enter a series of numbers and I will tell you which is the largest.\nEn
ter a 0 or negative number when you wish to terminate the program.\n");
scanf("%f", &number);
while (number != 0 && number > 0) {
printf("Enter your next number: ");
scanf("%f", &number);
if (number >= highestnumber) {
number = highestnumber; }
else if (number < highestnumber) {
highestnumber = highestnumber; }
} // end of while loop
printf("The highest number is: %2f\n", highestnumber);
return 0;
}
Anyway, the program works as far as it allows you to enter as many numbers as you want, until you hit 0 or a negative, then it terminates.
The problem is that no matter what the highest number was, the program always says that the highest number is 0.
There must be some relation between the highestnumber and number that I am missing, but does anyone have any ideas? This is due tomorrow and the chapter has no analogous problems that will help me.
Thanks a bunch
-P