Gpa Calc

Pages: 12
I am making a program in which i want to teke the Grade from the user and calculate his semester Gpa.

There are 102 errors in this program.

So plz help me to solve this problem

THanks all of you my dears.


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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
using namespace std;

void main()
{
char grade1[5];
char grade2[5];
char grade3[5];
char grade4[5];
char grade5[5];

double gpa1,gpa2,gpa3,gpa4,gpa5;
double add,SGPA1;

 cout<<"Enter grade of Calculus1 :"<<endl;
 cin>>grade1;

if(grade1=='A'||grade1=='a')
	 gpa1=4;
else if(grade1==Am||grade1==am)
	 gpa1=3.67;
else if(grade1==Bp||grade1==bp)
	 gpa1=3.33;
else if(grade1=='B'||grade1=='b')
	 gpa1=3.00;
else if(grade1==Bm||grade1==bm)
	 gpa1=2.67;
else if(grade1==Cp||grade1==cp)
	 gpa1=2.33;
else if(grade1=='C'||grade1=='c')
	 gpa1=2.00;
else if(grade1==Cm||grade1==cm)
	 gpa1=1.67;
else if(grade1==Dp||grade1==dp)
	 gpa1=1.33;
else if(grade1=='D'||grade1=='d')
	 gpa1=1.00;
else if(grade1=='F'||grade1=='f')
	 gpa1=0;
else if(grade1=='I'||grade1=='i')
	 gpa1=0;


 cout<<"Enter grade of Intro to Information Technology :"<<endl;
 cin>>grade2;

if(grade2=='A'||grade2=='a')
	 gpa2=4;
 else if(grade2=='Am'||grade2=='am')
	 gpa2=3.67;
else if(grade2=='Bp'||grade2=='bp')
	 gpa2=3.33;
else if(grade2=='B'||grade2=='b')
	 gpa2=3.00;
else if(grade2=='Bm'||grade2=='bm')
	 gpa2=2.67;
else if(grade2=='Cp'||grade2=='cp')
	 gpa2=2.33;
else if(grade2=='C'||grade2=='c')
	 gpa2=2.00;
else if(grade2=='Cm'||grade2=='cm')
	 gpa2=1.67;
else if(grade2=='Dp'||grade2=='dp')
	 gpa2=1.33;
else if(grade3=='D'||grade2=='d')
	 gpa2=1.00;
else if(grade2=='F'||grade2=='f')
	 gpa2=0;
else if(grade2=='I'||grade2=='i')
	 gpa2=0;


 cout<<"Enter grade of Physics :"<<endl;
 cin>>grade3;

if(grade3=='A'||grade3=='a')
	 gpa3=4;
 else if(grade3=='Am'||grade3=='am')
	 gpa3=3.67;
else if(grade3=='Bp'||grade3=='bp')
	 gpa3=3.33;
else if(grade3=='B'||grade3=='b')
	 gpa3=3.00;
else if(grade3=='Bm'||grade3=='bm')
	 gpa3=2.67;
else if(grade3=='Cp'||grade3=='cp')
	 gpa3=2.33;
else if(grade3=='C'||grade3=='c')
	 gpa3=2.00;
else if(grade3=='Cm'||grade3=='cm')
	 gpa3=1.67;
else if(grade3=='Dp'||grade3=='dp')
	 gpa3=1.33;
else if(grade3=='D'||grade3=='d')
	 gpa3=1.00;
else if(grade3=='F'||grade3=='f')
	 gpa3=0;
else if(grade3=='I'||grade3=='i')
	 gpa3=0;


 cout<<"Enter grade of Communication Skills :"<<endl;
 cin>>grade4;

if(grade4=='A'||grade4=='a')
	 gpa4=4;
 else if(grade4=='Am'||grade4=='am')
	 gpa4=3.67;
else if(grade4=='Bp'||grade4=='bp')
	 gpa4=3.33;
else if(grade4=='B'||grade4=='b')
	 gpa4=3.00;
else if(grade4=='Bm'||grade4=='bm')
	 gpa4=2.67;
else if(grade4=='Cp'||grade4=='cp')
	 gpa4=2.33;
else if(grade4=='C'||grade4=='c')
	 gpa4=2.00;
else if(grade4=='Cm'||grade4=='cm')
	 gpa4=1.67;
else if(grade4=='Dp'||grade4=='dp')
	 gpa4=1.33;
else if(grade4=='D'||grade4=='d')
	 gpa4=1.00;
else if(grade4=='F'||grade4=='f')
	 gpa4=0;
else if(grade4=='I'||grade4=='i')
	 gpa4=0;



 cout<<"Enter grade of Religious Studies :"<<endl;
 cin>>grade5;

if(grade5=='A'||grade5=='a')
	 gpa5=4;
 else if(grade5=='Am'||grade5=='am')
	 gpa5=3.67;
else if(grade5=='Bp'||grade5=='bp')
	 gpa5=3.33;
else if(grade5=='B'||grade5=='b')
	 gpa5=3.00;
else if(grade5=='Bm'||grade5=='bm')
	 gpa5=2.67;
else if(grade5=='Cp'||grade5=='cp')
	 gpa5=2.33;
else if(grade5=='C'||grade5=='c')
	 gpa5=2.00;
else if(grade5=='Cm'||grade5=='cm')
	 gpa5=1.67;
else if(grade5=='Dp'||grade5=='dp')
	 gpa5=1.33;
else if(grade5=='D'||grade5=='d')
	 gpa5=1.00;
else if(grade5=='F'||grade5=='f')
	 gpa5=0;
else if(grade5=='I'||grade5=='i')
	 gpa5=0;




cout<<"GPA in Calculus1 :"<<gpa1<<endl;
cout<<"GPA in Intro to Information Technology :"<<gpa2<<endl;
cout<<"GPA in Physics :"<<gpa3<<endl;
cout<<"GPA in Communication skills :"<<gpa4<<endl;
cout<<"GPA in Religious Studies :"<<gpa5<<endl;

add=(gpa1+gpa2+gpa3+gpa4+gpa5);
SGPA1=(add*4)/17;

cout<<SGPA1<<endl;
}
There are 102 errors in this program.

Thats a lot of errors without any indication to what any of the errors are. Almost sounds like we would need to re-write the program for you so please post some of the errors given :)

Also, to neaten up your code you may want to change the input to uppercase/lowercase so that you don't have to have lines like if(grade5=='A'||grade5=='a')... all throughout your program
Last edited on
All of those errors come from everything that looks like this: grade3=='bm'
Single quotes translate the single character inside to an integer. For example, 'A'==65 (ASCII). It's illegal to have more than one character inside them.
If you don't want to rewrite a lot of code, input grades into an std::string and replace all ' with ".

Also, use functions for the love of god!
what is meant by this sentece dear
" to neaten up your code you may want to change the input to uppercase/lowercase so that you don't have to have lines like if(grade5=='A'||grade5=='a')..."

THese are the only 2 errors which are coming again and again:

error C2446: '==' : no conversion from 'int' to 'char *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
error C2040: '==' : 'char [5]' differs in levels of indirection from 'int'

thanks
How about you try what I told you instead of trying to find mistakes in my reasoning?
Dear buddy i have removed all single quotes from double char.
but even there is no effect.


yah dear but its same as 102 errors
Did you change the types of grade# to std::string?
helios is saying to transform your text to either uppercase/ or lowercase, so you dont have all of those pointless conditions(grade == 'A'||grade == 'a'), because it doesnt look too great,
your are also using void main() (get that out of there, void main() is a lie, it still returns a value), google c++ functions, this code could be simplified into probably a 4th of what it is now
Also, use functions for the love of god!

Haha had to LOL at that!

What I mean is that it's tedious to have to write lines like if(grade5=='A'||grade5=='a')... so instead, once you have got your input you can use something like:

1
2
3
4
5
6
    char str[80] = "ThIs Is A tEsT";
    
    for(int i=0;str[i];i++)
     if(isupper(str[i])) str[i] = tolower(str[i]);
    
    cout << str;


This takes the input, checks each character to see if it is uppercase and if so changes it to lower case, then you only have to check if it was "a" instead of "A" || "a". And, as Helios wonderfully said, you can make this a function and send all inputs to it thus making your code a lot better!
Last edited on
Dear its something else to make my program beautiful
but at this time i just want to run this program by anyway.

so plz try to remove its errors

Looking back through this user's posts, I simply cannot take him seriously. The code seems (to me) to have been purposely created as complete crap. I believe him to be a troll.

Look at his User Profile. If he's going to the Institute of Space Technology in Pakistan, why doesn't he have an email address there instead of gmail and yahoo? The phone number he gives looks fake, too (I believe it has one too many numbers!).

And he says, "Everyone may contact me for discussion or for any problem specialy related C++," and puts under Skills "C++", which is hardly the case.

Something's fishy here.
Step 1: Change the types of grade1, grade2, grade3, grade4, and grade5 to std::string
Step 2: Replace all single quotes (') with double quotes (")
Step 3: Notice that some conditions are missing their quotes (lines 20, 22, 26, 28, 32, and 34). Add them.

Don't bother coming back to waste our time until you've done this.
Helios (or anyone actually) is there a function for what I have posted but for the use of std::string instead of Cstrings?
closed account (S6k9GNh0)
Here's my version of this. Instead of asking the user, the user asks it and it's also based on a GPA 4.0 scale (should work with others but I get weird results so stick with 4.0). And instead of excepting a letter (which isn't specific enough to calculate GPA anyways), I used a number.

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
#include <iostream>
#include <ctype.h>

float GradeToGPA(int grade, float gpa)
{
    if (!grade) //if (grade == 0) return 0.0
        return 0.0;

	gpa =  (100 - (gpa * 10));
	return ((grade - gpa) / 10);
}

int main(int argc, char ** argv)
{
    int gpa;

    if (argc < 2)
        return 1;
    else
    {
        int grades[argc-1];
        for (int x = 0; x < argc - 1; ++x)
        {
            grades[x] = atoi(argv[x + 1]);

            if (grades[x] > 100)
                grades[x] = 100;

            if (grades[x] < 70)
                grades[x] = 0;
        }

        for (int x = 0; x < argc - 1; ++x) std::cout << "Grade " << x << ": " << GradeToGPA(grades[x], 4) << std::endl;

        for (int x = 0; x <argc - 1; ++x) gpa += grades[x];

        std::cout << "Total GPA: " << gpa;
    }
}
Last edited on
mcleano: std::transform(str.begin(),str.end(),str.begin(),&tolower);
I may have accidentally inverted the last two parameters.
Thank you.
Dear ComputerGuip:

Ur program has 5 errors.
helios i couldn't get it to work:

transform(str.begin(),str.end(),str.begin(),&tolower);

error: 23 C:\Users\alan\Desktop\trial.cpp no matching function for call to `transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >)'

any light to shine? i tried messing about with it but no luck .
Last edited on
std::transform() is declared in <algorithm>
Pages: 12