I suggest you get your text book and review the section on loops and the section/chapter pertaining to condition statements.
Your fundamental flaw is not understanding the logic behind the if() statement.
Printable View
I suggest you get your text book and review the section on loops and the section/chapter pertaining to condition statements.
Your fundamental flaw is not understanding the logic behind the if() statement.
Code:#include <stdio.h>
int main()
{
int total;
int smallest;
int largest;
int counter;
int integer;
total = 0;
counter = 0;
largest = 0;
smallest = 9;
printf("Enter a one digit integer (0,1,2,3,.,8,9 or -1 to quit): ");
scanf("%d", &integer);
while( integer >=0)
{
total = total + integer;
counter = counter + 1;
if (integer > largest)
largest = integer;
if (integer < smallest)
smallest = integer;
printf("Enter a one digit integer (0,1,2,3,.,8,9 or -1 to quit): ");
scanf("%d", &integer );
}
if (count!=0)
{
printf( "The smallest digit entered was %d\n", smallest );
printf( "The largest digit entered was %d\n", largest );
printf( "The total of the digits entered was %d\n", total );
printf( "Goodbye!!\n" );
}
else
printf("No digits were entered\n\n\nGoodbye!!\n");
return 0;
}
Don't like to hand code to people but this may help you ONLY if you look at your text book while looking at this. Look at it, study it and understand how it works.Code:#include <stdlib.h>
#include <stdio.h>
int main() {
int high = 0, low = 9, sum=0, in=0;
while ( in != -1 ) {
printf("\nEnter a digit or -1 to quit: ");
scanf("%d", &in);
if ( in != -1 ) sum += in;
else
break;
if ( in >= high )
high = in;
else if ( in <= low )
low = in;
}
printf("\nThe smallest digit entered was: %d\n", low);
printf("The largest digit entered was: %d\n", high);
printf("The total of the digits entered was: %d\n", sum);
return 0;
}
Nate