This program should use an array to store percentage grades in the range from 0
ID: 3774750 • Letter: T
Question
This program should use an array to store percentage grades in the range from 0 to 100 (inclusive). The program should allow the user to indicate when he or she is done entering grades. When the user is done entering grades, the program should print out the grades entered. Your C code must be both well-formatted and well-commented.
Here is what I have:
#include <stdio.h>
int main(){
short int GetScore(0);
char LetterGrade, input('y');
while (input == 'y' || input == 'Y') {
printf("Enter a numeric grade (0 - 100): ");
scanf_s("%d", &GetScore);
Lettergrade(getscore);}
return 0;
}
function Lettergrade(int grade)
{
if (GetScore >= 0 && GetScore <= 100) {
if (GetScore >= 0 && GetScore < 60) LetterGrade = 'F';
else if (GetScore >= 60 && GetScore < 70) LetterGrade = 'D';
else if (GetScore >= 70 && GetScore < 80) LetterGrade = 'C';
else if (GetScore >= 80 && GetScore < 90) LetterGrade = 'B';
else if (GetScore >= 90 && GetScore <= 100) LetterGrade = 'A';
printf(" For a numeric grade of %d, ", GetScore);
printf("the corresponding letter grade is %c. ", LetterGrade);
}
else
printf(" Invalid numeric grade! Please try again. ");
}
Explanation / Answer
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int main() {
char choice; // choice of user
int marksArray[50]; // array of marks
int marks;
int count=0;
char LetterGrade;
do{
printf("-------------------Please enter your choice--------------- Add marks(a) Quit(q) ");
scanf("%c",&choice); // getting user input
switch(choice){
case 'a':
printf("Please enter the marks between 0 to 100 ");
scanf("%d",&marks); // getting user input
marksArray[count]=marks;// adding the marks to array
count++;
break;
case 'q':
for(int i=0;i<count;i++){ // loop for printing all the grades
if (marksArray[i] >= 0 && marksArray[i] <= 100) { //conditions for the grade
if (marksArray[i] >= 0 && marksArray[i] < 60) LetterGrade = 'F';
else if (marksArray[i] >= 60 && marksArray[i] < 70) LetterGrade = 'D';
else if (marksArray[i] >= 70 && marksArray[i] < 80) LetterGrade = 'C';
else if (marksArray[i] >= 80 && marksArray[i] < 90) LetterGrade = 'B';
else if (marksArray[i] >= 90 && marksArray[i] <= 100) LetterGrade = 'A';
printf(" For a numeric grade of %d, ", marksArray[i]);// printing the marks
printf("the corresponding letter grade is %c. ", LetterGrade); // printing the grade associated with the mark
}else{
printf(" Invalid numeric grade!");
}
}
exit(1);
break;
}
}while(choice!='q');
return 0;
}
-------------------------------------------------------output-------------------------------------------------------------------------
-------------------Please enter your choice---------------
Add marks(a)
Quit(q)
a
Please enter the marks between 0 to 100
23
-------------------Please enter your choice---------------
Add marks(a)
Quit(q)
-------------------Please enter your choice---------------
Add marks(a)
Quit(q) q For a numeric grade of 23, the corresponding letter grade is F.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.