C++ Grade Book

//
// main.cpp
// School Book averaging Test
//
// Created by Hoekwater_Nicholas on 12/18/12.
// Copyright (c) 2012 Combatoid. All rights reserved.
//






#include <iostream>
using namespace std;
int main()
{
double usergrade;
double numgrade;
double count;
count = 1;
double average;
average = usergrade / numgrade;

int A = 90, a = 90;
int B = 80, b = 80;
int C = 70, c = 70;
int D = 60, d = 60;
int F = 0, f = 0;

cout << " Please enter the number of grades to average:\n";

cin >> numgrade;
while (count <= numgrade)
{
count = count + 1;
cout << " Please enter the percentage scored on each assignment(without %):\n";
cin >> usergrade;


if(usergrade >= 90)
{
cout << "This assignment scored an A.";}
else if(usergrade>= 80)
{

cout << "This assignment scored a B."; }
else if(usergrade >= 70)
{

cout << "This assignment scored a C.";
}
else if(usergrade >= 60)
{

cout << "This assignment scored a D.";
}
else if(usergrade <= 59)
cout << "This assignment scored an F.";
}

double newusergrade = usergrade + newusergrade;

//Watermelon//

count++;
{

}


if(average>= 90)
{
cout << "Your average grade is an A.";}
else if(average>= 80)
{

cout << "Your average grade is a B."; }
else if(average >= 70)
{

cout << "Your average grade is a C.";
}
else if(average >= 60)
{

cout << "Your average grade is a D.";
}
else if(average <= 59)
cout << "Your average grade is an F.";
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int A = 90, a = 90;
int B = 80, b = 80;
int C = 70, c = 70;
int D = 60, d = 60;
int F = 0, f = 0;

cout << " Please enter the number of grades to average:\n";
cin >> numgrade;
while (count < numgrade)
{
cout << " Please enter grade in letter format:\n";
cin >> usergrade;
cout << " You entered " << usergrade << ".\n";
totalgrades = usergrade + totalgrades;

C++ doesn't work like that (actually, I don't know of any language that does). You would first need to handle the input, then, depending on what character the user entered, you would add that value to total grades. This is a tricky process and I believe you'd be better off entering the grades as a number (that's not to say that's it's impossible, however).
I believe in the "totalgrades = usergrade + totalgrades" is adding a character to an intergral. Take a look at that and I think you might know how to take it from there.
As easygoing has said the totalgrades = usergrade + totalgrades declaration is wrong. When you add a char to an int it takes the character's integers value and adds that to the int. Take a look at an ASCII chart that should help you understand what is wrong.

If you want to continue using the char input you should use either a switch statement or a ton of if else statements.

for example
switch(usergrade) {
case 'A':
totalgrades += 90;
break;
}

This should help you get the ball rolling.
Last edited on
Try something like this


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	for(int cnt = 0; cnt < numOf; cnt++)
	{
		cout<<"Please enter your grade: ";
		cin>> grade;
		if(toupper(grade)== 'A')
			total = total + 90;
		else if (toupper(grade)=='B')
			total = total + 80;
		else if(toupper(grade)=='C')
			total = total + 70;
		else if(toupper(grade) =='D')
			total = total + 60;
		else if(toupper(grade)=='F')
			total = total + 50;
		else {}
	}

	average = total / numOf;
The issue with this code is that when you declare:
int a=10;
you're declaring a variable "a" that is equal to 90.

But when the user enters "a", he's entering a string and not the variable you declared.
This is what I fixed. I'm still getting errors. It seems to only repeat the sequence once.
//
// main.cpp
// School Book averaging Test
//
// Created by Hoekwater_Nicholas on 12/18/12.
// Copyright (c) 2012 Combatoid. All rights reserved.
//






#include <iostream>
using namespace std;
int main()
{
char usergrade;
int totalgrades = 0;
double numgrade;
double count;
int average = 0;
int A = 90, a = 90;
int B = 80, b = 80;
int C = 70, c = 70;
int D = 60, d = 60;
int F = 0, f = 0;

cout << " Please enter the number of grades to average:\n";

cin >> numgrade;
while (count <= numgrade)
{
count = count + 1;
cout << " Please enter the percentage scored on each assignment(without %):\n";
cin >> usergrade;
break;
if(usergrade >= 90)
{
cout << "This assignment scored an A.";}
else if(usergrade>= 80)
{

cout << "This assignment scored a B."; }
else if(usergrade >= 70)
{

cout << "This assignment scored a C.";
}
else if(usergrade >= 60)
{

cout << "This assignment scored a D.";
}
else if(usergrade <= 59)
cout << "This assignment scored an F.";
}

double newusergrade;
newusergrade = usergrade + newusergrade;
//Watermelon//

count++;
{

}
average = newusergrade / numgrade;

if(average>= 90)
{
cout << "Your average grade is an A.";}
else if(average>= 80)
{

cout << "Your average grade is a B."; }
else if(average >= 70)
{

cout << "Your average grade is a C.";
}
else if(average >= 60)
{

cout << "Your average grade is a D.";
}
else if(average <= 59)
cout << "Your average grade is an F.";
}
Last edited on
Topic archived. No new replies allowed.