I wrote this code and it all works great, but as you'll notice at the end, I need to prompt the user to enter Y or N. If they enter N, then the program ends, I can do that. But if the user enter Y, the program need to ask for the info to be typed in again. How can I do this?
I'm not asking you guys to write it for me, just help me get started with that.
Code:
#include <stdio.h>
char first, last, GetLetterGrade, x;
float test_one, test_two, test_three;
float test_one_score, test_two_score, test_three_score;
float averageGrade;
int main()
{
//Get the maximum scores.
printf("Please enter the maximum score possible for test one: ");
scanf("%f", &test_one);
printf("Please enter the maximum score possible for test two: ");
scanf("%f", &test_two);
printf("Please enter the maximum score possible for test three: ");
scanf("%f", &test_three);
//Get students name.
printf("\nEnter your first and last name initials: ");
scanf(" %c%c", &first, &last);
//Get student test grades Checks for proper input.
printf("\n\nEnter your test one score: ");
scanf("%f", &test_one_score);
if(test_one_score < 0 || test_one_score > test_one){
printf("\nInvalid score, the valid range is : 0-%.2f\nEnter correct score:", test_one);
scanf("%f", &test_one_score);
}
printf("Enter your test two score: ");
scanf("%f", &test_two_score);
if(test_one_score < 0 || test_two_score > test_two){
printf("\nInvalid score the valid range is : 0-%.2f\nEnter correct score:", test_two);
scanf("%f", &test_two_score);
}
printf("Enter your test three score: ");
scanf("%f", &test_three_score);
if(test_one_score < 0 || test_three_score > test_three){
printf("\nInvalid score, the valid range is : 0-%.2f\nEnter correct score:", test_three);
scanf("%f", &test_three_score);
}
//Calculate average grade.
averageGrade = (test_one_score + test_two_score + test_three_score)/(test_one + test_two + test_three) * 100;
//Output student's info.
printf("\nStudent's initials: %c%c", first, last);
printf("\nAverage Score: %.2f", averageGrade);
//Output letter grade.
if(averageGrade >= 90){
printf("\nLetter grade: A");
}
else if((averageGrade >= 80) && (averageGrade < 90)){
printf("\nLetter grade: B");
}
else if((averageGrade >= 70) && (averageGrade < 80)){
printf("\nLetter grade: C");
}
else if((averageGrade >= 60) && (averageGrade < 70)){
printf("\nLetter grade: D");
}
else if(averageGrade < 60){
printf("\nLetter grade: F");
}
//Another student.
printf("\n\nCalculate another student grade (Enter Y for Yes, N for No): ");
scanf(" %c", &x);
return 0;
}