this is a simple program that lets us practice loops. I am having a problem with loops because they are going against every core of my mathematical being... Anyway, the user can input any integer, once -99 is entered the loop is exited and the output is the greatest integer that was entered. I can see that the program would have to loop to keep asking for the input and somehow keep comparing previous input to the new one to determine the largest number. So far I have this:
#include <stdio.h>
int main(void)
{
int i, a, largest;
printf("please enter integer:");
scanf("%d",&a);
while (a!=-99){
printf("please enter integer:");
scanf("%d", &a);
}
if(a>"%d",a)
a=largest;
printf("largest integer is %d", a);
return 0;
}
with the last part being my attempt to get the largest number as the output but it does not work. It exits the loop at -99 and returns a nonsense value stored somewhere at comp. memory. I think that if function is the one two use to compare the numbers, but am not sure how to get them to store and retreive. Any advise would be appreciated.
#include <stdio.h>
int main(void)
{
int i, a, largest;
printf("please enter integer:");
scanf("%d",&a);
while (a!=-99){
printf("please enter integer:");
scanf("%d", &a);
}
if(a>"%d",a)
a=largest;
printf("largest integer is %d", a);
return 0;
}
with the last part being my attempt to get the largest number as the output but it does not work. It exits the loop at -99 and returns a nonsense value stored somewhere at comp. memory. I think that if function is the one two use to compare the numbers, but am not sure how to get them to store and retreive. Any advise would be appreciated.