Hi,i'm still new for c++ programming..can anyone help me with this coding..this is the question..
Write C++ program that reads student scores, finds the best score, and then assign grades based on the following scheme:
Grade is A if score is >= best – 10; Grade is D if score >= 40;
Grade is B if score is >= best – 20; Grade is F otherwise.
Grade is C if score is >= best – 30;
The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. Below shows a sample run:
Enter the number of students: 4
Enter 4 scores: 40 55 70 58
Student 1 score is 40 and grade is C
Student 2 score is 55 and grade is C
Student 2 score is 55 and grade is A
Student 2 score is 55 and grade is B
This is the code so far:
#include <iostream>
#include <vector>
using namespace std;
int main() {
double num, best;
vector <int> score;
vector <char> grade;
cout<<"Enter the number of students: "; cin>>num;
cout<<"Enter "<<num<<" scores: ";
for (int i = 0; i < num; i++) {
cin>>score[i];}
best = score[0];
for (int i = 0; i < num; i++) {
if (score[i] > best) best = score[i];}
for (int i = 0; i < num; i++) {
if (score[i] >= -10) grade[i] = 'A';
else if (score[i] >= -20) grade[i] = 'B';
else if (score[i] >= -30) grade[i] = 'C';
else if (score[i] >= -40) grade[i] = 'D';
else grade[i] = 'F';}
for (int i = 0; i < num; i++) {
cout<<"Student "<<i + 1<<" score is "<<score[i]<<" and grade is "<<grade[i]<<endl;
}
// Write C++ program that reads student scores, finds the best score, and then
// assign grades based on the following scheme:
// Grade is A if score is >= best – 10; Grade is D if score >= 40;
// Grade is B if score is >= best – 20; Grade is F otherwise.
// Grade is C if score is >= best – 30;
// The program prompts the user to enter the total number of students, then
// prompts the user to enter all of the scores, and concludes by displaying
// the grades. Below shows a sample run:
// Enter the number of students: 4
// Enter 4 scores: 40 55 70 58
// Student 1 score is 40 and grade is C
// Student 2 score is 55 and grade is C
// Student 2 score is 55 and grade is A
// Student 2 score is 55 and grade is B
#include <iostream>
#include <vector>
void waitForEnter();
int main()
{
std::cout<<"Enter the number of students: ";
int num = 0;
std::cin >> num;
std::cout << "Enter " << num << " scores: ";
std::vector <int> scores;
int best = 0;
for (int i = 0; i < num; i++) {
int tmp = 0;
std::cin >> tmp;
scores.push_back(tmp);
if(tmp > best) { best = tmp; }
}
for (int i = 0; i < num; i++) {
std::cout << "Student " << i + 1 << " score is " << scores.at(i)
<<" and grade is ";
if (scores.at(i) >= -10) { std::cout << "A\n"; }
elseif (scores.at(i) >= -20) { std::cout << "B\n"; }
elseif (scores.at(i) >= -30) { std::cout << "C\n"; }
elseif (scores.at(i) >= -40) { std::cout << "D\n"; }
else { std::cout << "F\n"; }
}
return 0;
}
I think what jlb is telling you is you aren't respecting the assignment specifications when you evaluate the grades starting from the scores. You're missing a point; just read them more carefully.
i donn't exactly understand what you're trying to say..can u explain it..
In your if statements where are you do the computations?
// Grade is A if score is >=best – 10; Grade is D if score >= 40;
// Grade is B if score is >= best – 20; Grade is F otherwise.
// Grade is C if score is >= best – 30;
And you still haven't actually asked a question. Maybe "u explain it", the problem that is.