Homework Help Due MON

A

Allens Mail

Help,
Due Mon
I cant find the error. Keeps saying illegal token } have gone though code
and balance all French braces and parenthesis. Please help going crazy.
Code below
Thanks
Allen

//**************************************************************************
*******
// This program calculates your GPA for grades that are entered for a
unknown *
// number of classes for a student. GPA is calculated by taking the grade
value *
// times the unit value to get points. Points and units are running totals
*
// A grade of Q will end the program and the GPA is calculated by dividing
the *
// total number of points divided by total number os units. *
//**************************************************************************
*******

#include <iostream>
#include <iomanip>
using namespace std;

void main(void)
{

int GetGrade(int gradePoints);
float GetUnits(float uVal);

//Declaration programmer information
const char MY_NAME[25]= "Allen Mecum"; //progrqammer name
const char SECTION[25]= "CIS 1A M W 8-11:35am"; //class section
const char DATE[11]="07/02/2003"; //current date
const char DUEDATE[11]="07/07/2003"; //due date

// User Enters Grade and Units for class.
cout << "\nName: "<<MY_NAME << "\n";
cout << "Section: " << SECTION << "\n";
cout << "Date: " << DATE << "\n";
cout << "Due date:" << DUEDATE << "\n\n\n";

//GetGradeVal*UnitVal=totalPoints
cout << GetGrade << " and " << GetUnits;
}

//*********************************END
MAIN*************************************************

//Void Function GetGrade obtains input from the user and checks to see that
it is valid.
//It continues to prompt the user for a letter grade while the grade entered
is not
//an A, B, C, D, F or Q.

int GetGrade(int gradePoints)
{
char grade;


const int GRADEA=4;
const int GRADEB=3;
const int GRADEC=2;
const int GRADED=1;
const int GRADEF=0;


do
{
cout << "Please enter you grade (A-F, 'Q' to quit):";
cin >> grade;

gradePoints=0; // resets Temp locations to 0

switch(grade)
{
case 'a' :
case 'A' : gradePoints=GRADEA;
break;
case 'b' :
case 'B' : gradePoints=GRADEB;
break;
case 'c' :
case 'C' : gradePoints=GRADEC;
break;
case 'd' :
case 'D' : gradePoints=GRADED;
break;
case 'f' :
case 'F' : gradePoints=GRADEF;
break;
case 'q' :
case 'Q' : gradePoints=0;
break;
default : cout<<"***** INVAILD ENTRY *****\n\n";
break;
}

}
while (grade!='Q' && grade!='q');
return gradePoints;
}
//***********************************END
GetGrade****************************************

//Void Function GetUnits obtains from the user and checks to see that it is
vailid.
//It continues to prompt the user for a unit valuse while the units are not
in
//the range 0.0-9.0

float GetUnits(float uVal)
{

do
{
cout << "Enter the unit value:";
cin >> uVal; //stores temp units for calculation

if (uVal<0.0 || uVal> 9.0)
{
cout<<"Invaild Entry";
}
else
{
return uVal;
}
}
}
//*************************************END
GetUnits********************************************
 
B

Brian MacBride

Allens Mail said:
Help,
Due Mon
I cant find the error. Keeps saying illegal token } have gone though code
and balance all French braces and parenthesis. Please help going crazy.
Code below
Thanks
Allen

// Snip a-bunch-a-code...
float GetUnits(float uVal)
{

do
{
cout << "Enter the unit value:";
cin >> uVal; //stores temp units for calculation

if (uVal<0.0 || uVal> 9.0)
{
cout<<"Invaild Entry";
}
else
{
return uVal;
}
// }

// 'do' needs a 'while'
} while (...);

}
// *************************************END
// GetUnits********************************************

Regards

Brian
 
S

Sam Holden

Help,
Due Mon
I cant find the error. Keeps saying illegal token } have gone though code
and balance all French braces and parenthesis. Please help going crazy.
Code below
Thanks
Allen

"do" is not a stand alone element in C++, the construct is called "do while"
for a reason.

There are also a bunch of things which while syntactically correct
are incorrect.
 
C

Chris Thompson

Help,
Due Mon

Several people have pointed out several errors you have made.
//GetGradeVal*UnitVal=totalPoints
cout << GetGrade << " and " << GetUnits;

Additionally, this should be:
cout << GetGrade() << " and " << GetUnits();
 
T

Thomas Matthews

Allens said:
Help,
Due Mon
I cant find the error. Keeps saying illegal token } have gone though code
and balance all French braces and parenthesis. Please help going crazy.
Code below
Thanks
Allen
[snip]

I'll point out some improvements to your code that the other repliers
haven't.

//Void Function GetGrade obtains input from the user and checks to see that
it is valid.
//It continues to prompt the user for a letter grade while the grade entered
is not
//an A, B, C, D, F or Q.

int GetGrade(int gradePoints)
{
char grade;


const int GRADEA=4;
const int GRADEB=3;
const int GRADEC=2;
const int GRADED=1;
const int GRADEF=0;


do
{
cout << "Please enter you grade (A-F, 'Q' to quit):";
cin >> grade;

gradePoints=0; // resets Temp locations to 0

switch(grade)
{
case 'a' :
case 'A' : gradePoints=GRADEA;
break;

There is a function called 'toupper' which converts a
character (letter) to upper case. It's cousin is
'tolower' which converts to lower case. The standard
practice is to convert the character to upper or
lower case before comparing, which eliminates having
to check for both cases.
case 'b' :
case 'B' : gradePoints=GRADEB;
break;
case 'c' :
case 'C' : gradePoints=GRADEC;
break;
case 'd' :
case 'D' : gradePoints=GRADED;
break;
case 'f' :
case 'F' : gradePoints=GRADEF;
break;
case 'q' :
case 'Q' : gradePoints=0;
break;
default : cout<<"***** INVAILD ENTRY *****\n\n";
break;
}

}
while (grade!='Q' && grade!='q');
return gradePoints;
}

The above function implements an associative array,
also known as mapping (you are mapping one value to
another).

You can replace the above switch statment with either
an {array} table look-up or with a std::map container.
Using the map container, you function reduces to:
grade_points = grade_to_points_map[grade];
{provided that the input value has already been
filtered).

//***********************************END
GetGrade****************************************

//Void Function GetUnits obtains from the user and checks to see that it is
vailid.
//It continues to prompt the user for a unit valuse while the units are not
in
//the range 0.0-9.0

float GetUnits(float uVal)
{

do
{
cout << "Enter the unit value:";
cin >> uVal; //stores temp units for calculation

if (uVal<0.0 || uVal> 9.0)
{
cout<<"Invaild Entry";
}
else
{
return uVal;
}
}
}
//*************************************END
GetUnits********************************************

Remember that floating (and double) values should never
be compared to exact constants. To compare for exact,
one should use a tolarance, such as 0.005 or so.

Also, check 'cin' for failures. If you are expecting
the user to enter a character, the user could enter
a number instead. When expecting a float and the
user enters "hello", your program should gracefully
handle the error.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top