Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have been trying to make create this program, it's kinda hard for me to get help in real life because I'm the only computer science student in my second semester.

this is c++. I have to use arrays
I have to make a program that shows grades, based on marks. The number of students depends on the user input.

grade A >=90
grade B >=80
grade C >=70
grade D >=60
grade F <=59

based on the homework my lecturer has given me, the output has to be like this

Enter the number of students: 4
Enter 4 marks: 40 55 70 58
student 0 mark is 40 and grade is C
student 1 mark is 55 and grade is B
student 2 mark is 70 and grade is A
student 3 mark is 58 and grade is B

What I have tried:

This is my code: 

#include<iostream>
using namespace std;
int main(){
int students;
int mark;
int x;
char grade[6]={'A','B','C','D','F','\0'};
cout<<"enter the number of students"<<endl;
cin>>students;
cout<<"enter "<<students<<" marks "<<endl;
for(x=0;x<students;x++){
cin>>mark;
if(mark>=90)
grade[0];
else if(mark>=80)
grade[1];
else if(mark>=70)
grade[2];
else if(mark>=60)
grade[3];
else
grade[4];

cout<<"student "<<students<<" mark is "<<mark<<" and grade is "<<grade[x];
}
}

I don't know what to do anymore. Help me
Posted
Updated 6-Feb-17 21:58pm

This code:
if(mark>=90)
grade[0];
else if
Doesn't do anything - you access the grade character you want, but you don't do anything with it.
Before the if test, create a char variable called currentGrade and inside each if assign it to the grade you want:
if(mark>=90)
currentGrade = grade[0];
else if
You can then output the grade from currentGrade after all the tests are complete in your cout statement instead of grade[x]:
cout<<"student "<<students<<" mark is "<<mark<<" and grade is "<<currentGrade;

Give it a try and see what happens!
 
Share this answer
 
Comments
CPallini 7-Feb-17 3:24am    
5.
You also posted this question in the Managed C++ forum. Please do not repost.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900