473,513 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Homework Help Due MON

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****************************************** **

Jul 19 '05 #1
4 2963

"Allens Mail" <me***@pacbell.net> wrote in message
news:%p**********************@newssvr13.news.prodi gy.com...
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

Jul 19 '05 #2
On Sun, 13 Jul 2003 22:53:47 GMT, Allens Mail <me***@pacbell.net> wrote:
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.

--
Sam Holden

Jul 19 '05 #3
On Sun, 13 Jul 2003 22:53:47 +0000, Allens Mail wrote:
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();
Jul 19 '05 #4
Allens Mail wrote:
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

Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1788
by: | last post by:
I have this question for homework in an intro perl class, I was hoping for some quick help on this please...here is the question Using the Perl programming language, please prepare the following...
7
1754
by: tjshadyluver | last post by:
ok i have gotten this damn project almost done but i am frustrated on this one step. getting 18-35 together and 36-50 and so on. here is my code how can i get them combined in one line instead of...
2
2265
by: N3TB1N | last post by:
Let me try again. I could use some help with this assignment, even though my teacher does not grade assignments.but because I need to know this stuff for a test very soon, but haven't been in...
11
1685
by: spawn | last post by:
but I've been struggling with this for far too long and I'm about to start beating my head against the wall. My assignment seemed simple: create a program that will cacluate the running total of...
8
29139
by: garyrowell | last post by:
I have been at this programme for hours trying to work out what is wrong. Any help would be very much appricated. Here is the breif I received. The program This week you are going to write three...
24
1716
by: Three Headed Monkey | last post by:
write a program in "C" language that computes 9^(8^(7^(6^(5^(4^(3^(2^1))))))) I tried #include <stdio.h> int pow(int n) { int i,power; power=n;
3
4215
by: alireza6485 | last post by:
I need to write a C# program that asks for a pattern and for each pattern beeps one and goes silence for 1 second. This is my code: for (int i=0;i< pattern; i++) { ...
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7539
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3234
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1596
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
802
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.