So I just made an account to ask this question. I was watching tutorial 26 of C and did my code a bit differently than in the video. When I run this, everything works fine until I enter the number of tests in which after that it just spams "Enter number of tests: " Why is it not going through?
float test = 0;
float average = 0;
printf("Enter number of tests: ");
scanf(" %.0f", &numberoftests);
printf("Enter test grades: ");
scanf(" %.1f", &grade);
average += grade;
}while(test != numberoftests);
average /= numberoftests;
printf("Average grades: %.1f from %.0f tests.\n", average, numberoftests);
Do while loops, help
Post a Reply
|Oldest Newest Rating|
· August 28, 2014
I believe it has something to do with your number of tests being a float value instead of an integer.
I tried running your code and it also returned me an infinite loop of text.
I made a few modifications which seems to make the code work better, have a look.
· September 5, 2014
the probleme is in the scanf(" %.0f", &numberoftests);
you should right it like that
scanf(" %f", &numberoftests);
and if you want 2 float afte the sem colone type it in the printf() function like this
printf("the results is %.2f", numberoftests);
· October 14, 2014
Hi buddy so i fixed your code. Check comments in code. Also after reading the coments for first code i did a same one but with using ints.
I want to share my own version of calculating average grades and i also provide same code as below but with comments http://pastebin.com/YkNaE5YL.
One of the most popular languages of all time.
|Bucky Roberts Administrator|