Hi, I'm having some trouble with trying to get the largest number in my do - while loop...not sure if this is the way to go...anyway this is what I have done so far & it's in C...the way it is at the moment it only outputs the last number you enter as the largest number;
#include<stdio.h>
#include<stdlib.h>
int main()
{
int n,m,i,max;
n=0;
m=0;
max=m;
do
{
printf("Enter the numbers:");
/*loops the program so that user can enter values*/
for(i=0;i<=m;i++)
scanf("%d",&m);
/*determines if it is the largest number entered if not then it ignores it*/
if(m>max)
max=m;
printf("The Largest Number is %d",m);
printf("Number of values enetered were: %d\n",i);
}
/*loops until user enters a value below 0 or a negative value*/
while(m>= 0);
return 0;
}
If there are no braces enclosing the statements after a for(), only the first statement after it is executed more than one time.
1 2 3 4 5 6 7 8 9 10
printf("Enter the numbers:");
/*loops the program so that user can enter values*/
for(i=0;i<=m;i++)
{
scanf("%d",&m);
if(m>max)
max=m;
}
printf("The Largest Number is %d",m);
printf("Number of values enetered were: %d\n",i);
Great, thanks man...i got it working but it keeps a running a tally of the largest number entered. All I really did was what you suggested & change the m to a max in 'printf("The Largest Number is %d\t",max);'
do
{
/*loops the program so that user can enter values*/
printf("Enter the numbers:");
for(i=0;i<=m;i++)
{
/*determines if it is the largest number entered if not then it ignores it*/
scanf("%d",&m);
if(m>max)
max=m;
}
printf("The Largest Number is %d\t",max);
printf("Number of values entered were: %d\n",i);
}
/*loops until user enters a value below 0 or a negative value*/
while(m>= 0);
return 0;
}