In my code everything works to a t but when you enter a 0 you get -1.jf? idk whats wrong.
any help would be appreaciated.
Code:#include "stdafx.h"
#include <conio.h>
int _tmain(int argc, _TCHAR* argv[])
{
int x;
int XCount;
int sum;
float average;
sum = 0;
XCount = 1;
printf( "Enter Integer 1:" );
scanf_s("%d", &x);
while ( x != 0 ){
sum = sum + x;
XCount = XCount + 1;
printf("Enter Integer %d:", XCount);
scanf_s("%d", &x);
}
average = ( float ) sum / (XCount - 1 );
printf( "*****************\n" );
printf( "You have entered %d non-zero numbers\n", XCount - 1);
printf( "The sum of these integers is %d\n", sum );
printf( "The average of these integers is %.2f\n", average );
printf( "*****************" );
getch();
return 0;
}