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

Home Posts Topics Members FAQ

Syntax Problems

47 New Member
I am trying to write a C++ program that tells the inputter what their letter grade is after they input their number grade I cant seem to make this program run. It is of the form if-then-else, and I dont want to make any changes to it expect for the if-then-else section and the variables if necessary?! Can someone help me!!!!!!!!


int main()
{
int score;
char grade;


// read in total score

cout << endl ;
cout << "Enter total score (float, must be <= 100) : " ;
cin >> score ;

//compute grade

if (score >= 85)
{grade = 'A'};
else if (score >= 75)
{grade = 'B'};
else if (score >= 65)
{grade = 'C'};
else if (score >= 55)
{grade = 'D'};
else {grade = 'F'};

// display the result

cout << endl ;
cout << "Your grade for CMIS 102 is: " << grade << endl ;

return (0); // terminate with success
Nov 30 '06 #1
6 1727
Banfa
9,065 Recognized Expert Moderator Expert
none of you statements

grade = '<SomeLetter>'

have the required ; at the end of them.

Instead you have put the ; outside the code block ({...})

Laying out you code ina more orderly fasion would probably help prevent making the same mistake in the future.

It is normal for the { to appear at the end of the if line or on the line below by it self.

It is normal for the } to appear on a line by it self at the end of the code block.
Nov 30 '06 #2
mohsin
19 New Member
HI
well paranthieses of main function is missing '}'
after when you return 0 to maion function
Nov 30 '06 #3
mohsin
19 New Member
also
in every case youy terminate the statement with } rather than ;
you must have to use ; before } remove these error it will work
inshaallah
Nov 30 '06 #4
sivadhas2006
142 New Member
I am trying to write a C++ program that tells the inputter what their letter grade is after they input their number grade I cant seem to make this program run. It is of the form if-then-else, and I dont want to make any changes to it expect for the if-then-else section and the variables if necessary?! Can someone help me!!!!!!!!


int main()
{
int score;
char grade;


// read in total score

cout << endl ;
cout << "Enter total score (float, must be <= 100) : " ;
cin >> score ;

//compute grade

if (score >= 85)
{grade = 'A'};
else if (score >= 75)
{grade = 'B'};
else if (score >= 65)
{grade = 'C'};
else if (score >= 55)
{grade = 'D'};
else {grade = 'F'};

// display the result

cout << endl ;
cout << "Your grade for CMIS 102 is: " << grade << endl ;

return (0); // terminate with success
Hi,

Try this...

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() 
  6. {
  7.    int 
  8.       nScore = 0;
  9.    char 
  10.       cGrade = '\0';
  11.  
  12.    // Get the total Score.
  13.    cout << "\nEnter total Score (int, must be <= 100) : " ; 
  14.    cin >> nScore ; 
  15.  
  16.    //Compute Grade
  17.    if (nScore >= 85)
  18.    {
  19.       cGrade = 'A';
  20.    }
  21.    else if (nScore >= 75)
  22.    {
  23.       cGrade = 'B';
  24.    }
  25.    else if (nScore >= 65)
  26.    {
  27.       cGrade = 'C';
  28.    }
  29.    else if (nScore >= 55)
  30.    {
  31.       cGrade = 'D';
  32.    }
  33.    else 
  34.    {
  35.       cGrade = 'F';
  36.    }
  37.  
  38.    // Display the Result.
  39.    cout << endl ; 
  40.    cout << "Your Grade for CMIS 102 is: " << cGrade << endl ; 
  41.  
  42.    return (0); // terminate with success
  43. }
  44.  
Regards,
M.Sivadhas.
Nov 30 '06 #5
AZRebelCowgirl73
47 New Member
thanks so much for the help! Trying to learn this alone has really become quite a task. Came across this site, by accident. Expect to be here alot! Thanks again for the help! I see that for the most part I had it, just need to space more and be more clear. Thanks
Nov 30 '06 #6
thefarmer
55 New Member
try this also:

#include <iostream.h>
#include <conio.h>
{

clrscr ();
// Enter the value of the grade
cout << " The grade is: ";
double grade;
cin >> grade;

if ( grade >= 85) cout << "A";
else if (grade >= 75)
cout << "B";
else if (grade >= 65)
cout << "C";
else if (grade >= 55)
cout << "D";
else
cout << "F- Failed";
getch ();
return 0;

}

regards,
Dec 1 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

699
33329
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it...
303
17422
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which...
35
2929
by: Moosebumps | last post by:
Does anyone here find the list comprehension syntax awkward? I like it because it is an expression rather than a series of statements, but it is a little harder to maintain it seems. e.g. you could do: result = for element in list: if element == 'blah':
24
2027
by: Steven Bethard | last post by:
I think one of the biggest reasons we're having such problems coming to any agreement on decorator syntax is that each proposal makes a number of syntax decisions, not just one. For decorators, I see the following decisions that must be made: 1) Indicator Proposals differ on how some sort of indicator of "decoratorhood" is use. These...
29
2477
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules" for when and how to use single quotes and double quotes in ASP? thanks! ---------------------- SQL = SQL & "WHERE '" &...
7
248437
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a particular surname in a particular town. I can select the records fine with this syntax (testing in Oracle SQL* Plus) SELECT NAMEINFO.LASTNAME,...
0
1845
by: Berthold Höllmann | last post by:
I have a default coding header # -*- coding: iso-8859-15 -*- in my python files. I now have Problems with this settings. I swithched to Python 2.4.1 under Windows. When I import files with the above coding header I get frequent syntax errors with files that work flawlessly under Linux. The Syntax error usually appear near continuation...
8
4318
by: tom | last post by:
I am new to SQL administration. >From a list of IDs that are the primary key in one table (i.e. Customer Table), I want to make changes in tables that use those IDs as a foreign key. Basically I want to say: If fk_ID is in list then do these statements to that record
177
6858
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are programming languages still being designed with C's syntax? These questions drive me insane. Every waking minute...
2
1433
by: Rick Strahl [MVP] | last post by:
I seem to have problems when working with large Windows Forms files. What happens is that hte editor looses its syntax color highlighting and Intellisense capability on large files. The code works - it compiles and runs fine, but the syntax color highlighting goes away. All formatting blows up too and the editor no longer helps with...
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7559
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7123
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4756
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.