Trying to convert pseudocode to C++

I can't seem to get this to this to work. Can anyone help me and t

Page 1 of 1

9 Replies - 2292 Views - Last Post: 08 March 2008 - 09:25 PM Rate Topic: -----

#1 Miller98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 08-March 08

Trying to convert pseudocode to C++

Post icon  Posted 08 March 2008 - 04:26 PM

#include "stdafx.h"

#include <iostream>

 using namespace std;

 int main() 
{

	float score;			//Score
	float grade;			//Grade

	 // read in total score 

	 cout << endl;
	 cout << "Enter total score (float, must be <= 100) : "; 
	 cin >> score;  
	 
			[color=#FF0000]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';
			if // score >= 55;
			if // score >= 65;
			if // score >= 75;
			if // score >= 85;[/color] 

	 // display the result 

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

	 return (0); // terminate with success 
} 





Here are my errors.

warning C4390: ';' : empty controlled statement found; is this the intent?
error C2181: illegal else without matching if
warning C4390: ';' : empty controlled statement found; is this the intent?
error C2181: illegal else without matching if
warning C4390: ';' : empty controlled statement found; is this the intent?
error C2181: illegal else without matching if
error C2059: syntax error : 'if'

Is This A Good Question/Topic? 0
  • +

Replies To: Trying to convert pseudocode to C++

#2 Miller98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 08-March 08

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 04:50 PM

#include "stdafx.h"

#include <iostream>

 using namespace std;

 int main() 
{

	float score;			//Score
	float grade;			//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';
			if // score >= 55;
			if // score >= 65;
			if // score >= 75;
			if // score >= 85;
 

	 // display the result 

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

	 return (0); // terminate with success 
} 




Ok, now I am getting the following error. Can't seem to figure this out. Help please.
error C2059: syntax error : 'if'

#include "stdafx.h"

#include <iostream>

using namespace std;

int main() 
{

	float score;			//Score
	float grade;			//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';
			if // score >= 55;
			[color=#FF0000]if // score >= 65;[/color]
			if // score >= 75;
			if // score >= 85;


	 // display the result 

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

	 return (0); // terminate with success 
}




Ok, now I am getting the following error. Can't seem to figure this out. Help please.
error C2059: syntax error : 'if'
Was This Post Helpful? 0
  • +
  • -

#3 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 05:12 PM

My guess is it's these:
            if // score >= 55;
            if // score >= 65;
            if // score >= 75;
            if // score >= 85;



Comment out all four lines and see what happens.
Was This Post Helpful? 0
  • +
  • -

#4 Miller98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 08-March 08

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 05:20 PM

I thought it was
if // score >= 55;
if // score >= 65;
if // score >= 75;
if // score >= 85;
but I have no clue on how to fix it.
Was This Post Helpful? 0
  • +
  • -

#5 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 05:24 PM

Comment out the damn lines, and it'll compile. They're incomplete if statements, so the compiler is choking on it.
Was This Post Helpful? 0
  • +
  • -

#6 Miller98  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 08-March 08

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 05:32 PM

Not really sure what you are meaning?

Quote

Comment out the damn lines, and it'll compile. They're incomplete if statements, so the compiler is choking on it.

Was This Post Helpful? 0
  • +
  • -

#7 letthecolorsrumble  Icon User is offline

  • Student of The Sun
  • member icon

Reputation: 27
  • View blog
  • Posts: 555
  • Joined: 07-November 07

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 05:38 PM

Try this one:

#include <iostream>

using namespace std ;

int main()
{

    float score ; //Score
    char grade ; //Grade should be char if you want to store ASCII characters

    // 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' ;
//commenting out using "//"
//            if // score >= 55;
//            if // score >= 65;
//            if // score >= 75;
//            if // score >= 85;


    // display the result

    cout << endl ;
    cout << "Your grade for course is: " << grade << endl ;

    return (0); // terminate with success
} 



Was This Post Helpful? 0
  • +
  • -

#8 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 07:18 PM

Thank you, letthecolorsrumble, I was about to say something that could have landed me in hot water.
Was This Post Helpful? 2

#9 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 08:15 PM

View PostMorphiusFaydal, on 8 Mar, 2008 - 05:24 PM, said:

Comment out the damn lines, and it'll compile. They're incomplete if statements, so the compiler is choking on it.


lol, getting a little aggravated?

sometimes it helps to explain WHY those lines will not compile...
Was This Post Helpful? 0
  • +
  • -

#10 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: Trying to convert pseudocode to C++

Posted 08 March 2008 - 09:25 PM

I thought I did. They're not complete if statements. I dunno how to make it any clearer. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1