i have infinite loops. why?
#include <stdio.h>
#include <conio.h>
int main()
{
int answer, num, count = 0, total = 0, max = 0;
float average;
do
{
clrscr();
printf("Enter an integer: ");
scanf("%i", &num);
while ( count < 3 && num > 0 )
{
count=count + 1;
total += num;
if ( num > max )
{
max = num;
}
printf("Enter next integer: ");
scanf("%i", &num);
}
if ( count > 0 )
{
printf("\n");
printf("The maximum number is %i\n", max);
printf("the count is %i\n", count);
printf("the total is %i\n", total);
average= (float)total / count;
printf("the average in two decimal point is %.2f\n", average);
}
else
printf("No valid number were entered\n");
printf("Another run? Y/N ");
scanf("%i", &answer);
} while ( answer != 'N');
return(0);
}
i have problems doing the while loop! help me out if possible . .
unsure about while ( answer !- 'N')???
thanks mate
i have modified, but i still cant read the char
#include <stdio.h>
#include <conio.h>
int main()
{
char answer;
int num, count, total, max;
float average;
clrscr();
do
{
count=0, total=0, num=0;
printf("\n");
printf("Enter an integer: ");
scanf("%d", &num);
while ( count < 3 && num > 0 )
{
count=count + 1;
total += num;
if ( num > max )
{
max = num;
}
printf("Enter next integer: ");
scanf("%d", &num);
}
if ( count > 0 )
{
printf("\n");
printf("The maximum number is %i\n", max);
printf("the count is %i\n", count);
printf("the total is %i\n", total);
average= (float)total / count;
printf("the average in two decimal point is %.2f\n", average);
printf("\n");
}
else
{
printf("No valid number were entered\n");
}
printf("End of run. Another run? Y/N: ");
answer=getchar();
}while ( answer !='N' || answer != 'n');
return(0);
}
Problems: the loops is soft of working, but can read char,
once i read char, i have an infinite loops . .