#include <iostream>
using  namespace std ;
int main() ; 

 {
      score and grade     // declare variables ;
 
      float total_score  // total weigted points ;

      char grade // letter  grade ;

      int A , B , C , D , F  ;	 	


	   // read in total score ;
	 
      cout << endl ;
      cout << "Enter total score (float, must be <= 100) : " ; 
      cin >> score ; 
	  	
	   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' ;
	 

	     // end if score
	 
	
     // display the result 

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

     return (0); // terminate with success
  

 }

This gives me an error - >.\Assignment 2.cpp(21) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Users\jashbela\Documents\Visual Studio 2008\Projects\Assignement 2\Assignement 2\Release\BuildLog.htm"
1>Assignement 2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Recommended Answers

All 25 Replies

Remove the ; from int main();

You're going to have more semicolon problems throughout your code. (See if else statements)

>Compiling...
1>Assignment 2.cpp
1>.\Assignment 2.cpp(23) : error C2065: 'score' : undeclared identifier
1>.\Assignment 2.cpp(23) : error C2146: syntax error : missing ';' before identifier 'and'
1>.\Assignment 2.cpp(25) : error C2065: 'and' : undeclared identifier
1>.\Assignment 2.cpp(25) : error C2146: syntax error : missing ';' before identifier 'grade'
1>.\Assignment 2.cpp(25) : error C2065: 'grade' : undeclared identifier
1>.\Assignment 2.cpp(25) : error C2144: syntax error : 'float' should be preceded by ';'
1>.\Assignment 2.cpp(27) : error C2144: syntax error : 'char' should be preceded by ';'
1>.\Assignment 2.cpp(29) : error C2144: syntax error : 'int' should be preceded by ';'
1>.\Assignment 2.cpp(36) : error C2065: 'score' : undeclared identifier
1>.\Assignment 2.cpp(38) : error C2065: 'score' : undeclared identifier
1>.\Assignment 2.cpp(40) : warning C4390: ';' : empty controlled statement found; is this the intent?
1>.\Assignment 2.cpp(43) : error C2181: illegal else without matching if
1>.\Assignment 2.cpp(43) : error C2065: 'score' : undeclared identifier
1>.\Assignment 2.cpp(45) : warning C4390: ';' : empty controlled statement found; is this the intent?
1>.\Assignment 2.cpp(47) : error C2181: illegal else without matching if
1>.\Assignment 2.cpp(47) : error C2065: 'score' : undeclared identifier
1>.\Assignment 2.cpp(49) : warning C4390: ';' : empty controlled statement found; is this the intent?
1>.\Assignment 2.cpp(52) : error C2181: illegal else without matching if
1>.\Assignment 2.cpp(52) : error C2065: 'score' : undeclared identifier
1>.\Assignment 2.cpp(54) : warning C4390: ';' : empty controlled statement found; is this the intent?
1>.\Assignment 2.cpp(57) : error C2181: illegal else without matching if
1>Build log was saved at "file://c:\Users\jashbela\Documents\Visual Studio 2008\Projects\Assignement 2\Assignement 2\Release\BuildLog.htm"
1>Assignement 2 - 17 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This is what I get when I remove!!!

Please help!!!!!! I don't know why?

1. Everything on one line after a // is commented out, including semicolons.
2. I'm assuming your "score and grade" text should be a comment. Make it one.
3. Your if/else statements aren't semicoloned properly.
4. Keep reading whatever you're learning C++ from. No offense, but it seems you don't yet have a firm grasp on syntax and how to form proper C++ statements.

Read up on the semi-colon. You have no idea yet how/when/where to use them. Your book is the best place to learn this simple stuff.

I fugured it out. semiclolons and varables ty

Hi guys last help please.I am going to copy and paste. It works gives me results but says variable grade used with out initializing. What shoud I do?

int main() 
{

     float score ;
     char grade ;

     // read in total score 

     cout << endl ;
     cout << "Enter total score (float, must be <= 100) : " ; 
     cin >> score ; 
     
     if (score>=85) 
		 cout <<"The grade is A " << endl ;
	 else if (score>=75) 
	     cout <<"The grade is B " << endl ;
	 else if (score>=65)
	     cout <<"The grade is C " << endl ;
	 else if (score>=55)
	     cout <<"The grade is D " << endl ;
	 else 
	     cout<<"The grade is F " << endl ;


     // display the result 

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

     return (0); // terminate with success

You never actually set the grade variable to anything, so you're printing a variable with 'nothing' in it. I say 'nothing' because an uninitialized variable is full of garbage, not exactly nothing.

So I still don't know what to do.

I still need help. Ty, I would so appreciate it. I tried to read and find out but there is no answer to this .

Ok, I don't know why but since I was having an error at that last line while debugging I took the line out
cout<< "your grade is " << endl

Now it debugs with out problem but need to know why?

I was simply frustrated so erased that line, lol

What does the word initialize mean?

I have no Idea so.......

Please help me under stand

commented: Stop bumping your thread with pointless replies. -4

I know the definition I just dont know what to do to initialize the variable . I have tried every thing

I know the definition I just dont know what to do to initialize the variable . I have tried every thing

Obviously not. What's the value of grade when you output it? Point to the line that loads the value you claim it has.

Ty though. Should I put

char grade // declare the grade ;

? Is this what i need?

I have tried setting grade = A but didnt work. so sorry to sound dumb but rally getting confused

TY

One more question , when i remove the line

cout<< " Your garde is" << grade << endl ;

at the end why does it work?

You're close with grade = A, but since grade is a char, A needs to be a char, so you'll need to wrap it in single quotes.

If I may make a suggestion.. I think you might need to learn from a different source if you haven't learned yet how to initialize a variable but you've learned cin & if statements. Just doesn't make sense to me.

Ty, for the help. I really haven't learned C++. In the class I am taking they want us to keep format, all I have to do declare variables and write if else statements. I am leaning this on my own. I figured out semicolon, if else , and variables. I kind of figured out cout and cin little bit.( i didn't have to, I was given that part)

Just was lost at erroe " variable grade is not initialized" and also why it works when I take last line out!

So you got everything figured out and working properly now?

This is how I made it.

#include <iostream>

using namespace std;

int main(){
    int score;
    
    cout << "Enter score: ";
    cin >> score;
    
    if(score > 100){
             cout << "Lies.";
    }
    else if (score >= 85){
             cout << "A";
    }
    else if (score >= 75){
             cout << "B";
    }
    else if (score >= 65){
             cout << "C";
    }
    else if (score >= 55){
             cout << "D";
    }
    else {
         cout << "F";
    }
    
    system("pause");
}

yes working now. ty for all the replies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.