Hi my name is Chris and I am currently enrolled in CMIS102 class. I am really banging my head :@(on multiple occasions) with my latest assignment.

I have read every forum, book, and troubleshooting guide there is but nothing out there that has helped me to find the result or problem on why my code returns errors or 'bugs'.

#include <iostream>

using namespace std ;

int main()
{


// declaring variables:
int A, B, C, D, F;
char grades[5] = {'A', 'B' , 'C' , 'D' , 'F'};

// read in total score

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

// assign grade

		if (score >= 90) then
			grade = ‘A’ ; 
				else if (score >= 80) 
					set grade = ‘B’;
				else if (score >= 70)
					set grade = ‘C’;
				else if (score >= 60)
					set grade = ‘D’;
				else
					set grade = ‘F' ;

			end if // end if score >= 55
		end if // end if score >= 65
	end if // end if score >= 75
end if // end if score >= 85

// display the result

cout << endl ;
cout << "Your grade for CMIS 102 is: " << grade << endl ;
return (0); // terminate with success
}

It comes back with the following errors...

error C2065: 'score' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'grade'
error C2065: '‘A’' : undeclared identifier (NOTE: it also says B, C, D, and F are undeclared as well)

It might be how I defined the variables but again, I am new to all of this and could use some guidance or help with this! It is due Sunday so I am hoping to have it complete by then

Thanks in advance

Recommended Answers

All 14 Replies

First thing You have to declare every variable before using it, so you have to define the score

float score;

Second why you use character array no need of this just use simple character variable

char grade;

no need of this declaration

int A, B, C, D, F;

Hope it help will helpful for you.
Best Of Luck

commented: Clarified what I was looking for! +0

prvnkmr194,

Thanks for the quick reply!

Hate to bother you again but how you I declare the float score?

I have entered in float score;

Do I need to state each grade after that?

I am still getting the same errors saying that A, B, C, D, F are undeclared?

I am using Visual Basic C++ 2010 if that helps

#include <iostream>

using namespace std ;

int main()
{


// declaring variables:
float score;
char grade;
int A, B, C, D, F;

// read in total score

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

// assign grade

		if (score >= 90) 
			grade = 'A' ; 
				else if (score >= 80) 
					 grade = 'B' ;
				else if (score >= 70)
					 grade = 'C' ;
				else if (score >= 60)
					 grade = 'D' ;
				else
					 grade = 'F';

			 // end if score >= 55
		 // end if score >= 65
	 // end if score >= 75
 // end if score >= 85

// display the result

cout << endl ;
cout << "Your grade for CMIS 102 is: " << grade << endl ;
return (0); // terminate with success
}

Everything works great except for the following ERROR:

warning C4101: 'B' : unreferenced local variable

Help?

I got it!

Thanks again for the help!

[edit]I know this is a little late but...[/edit]

>>I am using Visual Basic C++ 2010 if that helps
Here is your problem. There is no such thing as "Visual Basic C++". It's either Visual Basic or Visual C++. Is your class using the Basic or C++ language that is included with Visual Studio? The code you posted looks more like Basic than C/C++.

C/C++ doesn't have all the extra "fluff" keywords that Basic and pseudocode do. Everything has meaning and is short and to the point.

if (score >= 90) then
			grade = ‘A’ ; 
				else if (score >= 80) 
					set grade = ‘B’;
				else if (score >= 70)
					set grade = ‘C’;
				else if (score >= 60)
					set grade = ‘D’;
				else
					set grade = ‘F' ;
 
			end if // end if score >= 55
		end if // end if score >= 65
	end if // end if score >= 75
end if // end if score >= 85

There is no "then" or "end if" in C++, the if statement is simply "if" followed by either a single statement or a statement block:

//if with single statement
if (condition)
  statement;

//if with statement block:
if (condition) {
  statement1;
  statement2;
  statement3;
  //etc...
}

>>I have entered in float score
Sounds like you have it right. In C/C++ there is no "dim" or "declare" statement. Again, short and to the point:

//declare a float variable called score
float score;

In C/C++, the word "set" does not mean assignment, it means something different. When performing assignment, you state the variable name and the new value:

//assign the integer value 15 to the integer variable someNum
int someNum;  //declare an integer called "someNum"
someNum = 15; //assign the value 15 to "someNum"

>>I am still getting the same errors saying that A, B, C, D, F are undeclared?
Would have to see your current code to know what you did to cause this...

Mark this thread as solve if your problem is solve

I am working on the same project and I am getting A, B, C, D, F unrefernced could I get alittle help.

/****************************************************/

#include <iostream>

 using namespace std ;

 int main() 
{

	//Declaring varibles

    float score ;// Class Score  
	char grade ;// Class Grade
	int A, B, C, D, F;// Overall letter grade 
	
     // 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: " << grade << endl ; 

     return (0); // terminate with success



}

s

commented: Do NOT bump threads -- especially after a whopping 2 minutes! -3

remove ";" from line 53 that is make line 53 like this

cout << endl ;

rmove line no 12
that is

int A, B, C, D, F;

no need of declaring these variable

Thanks for the help. Everything is working great now. I was wondering if there is a way to limit the input on the score to not going over 100.

If statement.

Got your answers if you still need them...let me know. A lot depends on how your teacher wants you to do this. To illustrate array, to output only one grade, to allow for multiple score inputs?

I did the same programme but gives error

>.\Assignment 2.cpp(22) : 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 ==========

@jashbela
Start new thread to get help your question, and post your coding as well

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.