This program should use an array to store percentage grades in the range from 0
ID: 3780513 • 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.
I know this assignment doesn't have anything to do with letter grades. And I also know that the program should store the numeric grades and print them back out when the user says the input is complete and input loop should be a for loop that will not run more times than the number of items the array can hold. This is what I have so far:
#include
#include
int main() {
char choice; // choice of user
int percentArray[50];
int percentage;
int count=0;
char LetterGrade;
do{
printf("Enter percentage Add percentage(a) Quit(q) ");
return 0;
}
Explanation / Answer
Please find the required program along with its output. Please see the comments against each line for description :
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int main() {
char choice; // choice of user
int percentArray[50];
int percentage;
int count=0;
char LetterGrade;
for (count=0; count<50; count++){ //for loop to read the grades till array size
printf("-------------------Enter percentage--------------- Add marks(a) Quit(q) ");
cin >> choice; //read user choice
if(choice == 'a'){ //if user choice is a, then read the grade
cout << "Enter grade:" << endl;
cin >> percentage;
percentArray[count] = percentage; //add the grade to array
}
if(choice == 'q'){ //if the user choice is q, then exit the loop
break;
}
}
cout << "Grades are: " << endl;
for (int i=0; i<count; i++){ //print the readed grades
cout << percentArray[i] << " " << endl;
}
return 0;
}
----------------------------------------------------
OUTPUT:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.