What is the error in this code?

For a school homework i had to make a c++ program to generate a report card
so i made this program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream.h>
#include<conio.h>
void main()
{
float subject1,subject2,subject3,subject4,subject5,total,percentage;
char name,grade;
cout<<"Welcome User, The Following Program Will Help You Evaluate The Total \n";
cout<<",Percentage and Grade Using The Marks Obtained In 5 Subjects\n";
cout<<"Enter Your Name User :";
cin>>name;
cout<<"Enter The Marks Obtained In English(out of 100) :";
cin>>subject1;
cout<<"Enter The Marks Obtained In Chemistry(out of 100) :";
cin>>subject2;
cout<<"Enter The Marks Obtained In Physics(out of 100) :";
cin>>subject3;
cout<<"Enter The Marks Obtained In Computer Science/Infomatics(out of 100) :";
cin>>subject4;
cout<<"Enter The Marks Obtained In Mathematics/Biology(out of 100) :";
cin>>subject5;
total=subject1+subject2+subject3+subject4+subject5;
percentage=(total/500)*100;
if (percentage>90&&percentage<=100)
grade='A+';
else if (percentage>80&&percentage<=90)
grade='A';
else if (percentage>70&&percentage<=80)
grade='B';
else if (percentage>60&&percentage<=70)
grade='B';
else if (percentage>50&&percentage<=60)
grade='C+';
else if (percentage>40&&percentage<=50)
grade='C';
else if (percentage>32&&percentage<=40)
grade='D';
else
grade='E';
cout<<"Name:"<<name;
cout<<"Total Marks:"<<total;
cout<<"Percentage:"<<percentage;
cout<<"Grade:"<<grade;
getch();
}


The problem is that it does not take any values
So the main question is how do i fix the program

ps I have been learning C++ for 3 months so we don't have any arrays,at max we have iterations
How can you tell that it takes no values? What is the name of the first student? "Q"?

(You state that the "name" must be a single letter. Is that intentional?)
Replace
1
2
#include<iostream.h>
#include<conio.h> 


with
1
2
#include<iostream>
using namespace std;


EDIT: also, your main function should return an int.
Last edited on
How can you tell that it takes no values

It means the program is not compiling the cin command
and no, it is supposed to take multiple letters
it only takes the name(only the first letter) and then executes the program
i want it to take the full name,all the marks then evaluate the program

abhishekm71
we have not used the command using namespace std;
as i have said i started learning this language a mere 3 months
It means the program is not compiling the cin command

Of course, the cin command is being compiled.
You're not using it correctly. You've declared name as a single char (line 6). Use getline instead.
http://www.cplusplus.com/reference/string/string/getline/?kw=getline

we have not used the command using namespace std;

If you going to use cout, you have two choices.
1) using namespace std;
2) Or qualify every reference to cin and cout with std::
Last edited on
Three choices:
1) using namespace std; -- This is not recommended as it is too broad.
2) Qualify every reference to cin, cout and every other name from namespace std with std::
3) using std::cout; -- Usually the best if std::cout is used multiple times. It brings only the name cout into global scope.

Note that the std::getline stores a line into a variable of type std::string. It is very good to learn to use string. However, "using C++ effectively" and "learning to program" are two different things.
Topic archived. No new replies allowed.