Visual C++ Error system problem

Visual C++ error C2061: syntax error : identifier 'system' Pro

Page 1 of 1

4 Replies - 1683 Views - Last Post: 04 March 2009 - 10:07 PM Rate Topic: -----

#1 mvalor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 16-November 08

Visual C++ Error system problem

Post icon  Posted 03 March 2009 - 09:59 PM

:crazy: :crazy: :crazy: This is driving me nuts!
I keep having this error enter, no matter how much I review the coding.

"error C2061: syntax error : identifier 'system' Problem"
Maybe I am just tired or something, any way, this is the code:

*/
# include <iostream>
# include <cmath>

using namespace std;
int main()
{
//Declaring Values
char yesno;		// did the user enter yes or no?
char y,n;
float results;
float score; // number grade
float x; // Extra Credits
char grade;		// letter grade

//Making the Grade
cout  << "Enter a grade between 0 and 100:	";
cin >> score;

// Extra Credit or not extra credit...that is the question.
//Getting Extra Credit (Choice)

do {
	cout << "Is the student eligible for extra credit?"	<<"\n";
	cout << "1. y" ;
	cout << "2. n" ;
	cout << "Please make a selection: ";
	cin >>yesno;

	switch (yesno){
	case 'y': 
cout << "Enter Extra Credits:	" <<"\n";
cin >> x;
cout << "Extra Credit:" << x	  <<"\n";
results = (score + x);
		break;
	case 'n': 
		cout << "No extra credit entered. \n";
			results = (score + 0);
		break;
	default:
			cout << "Please enter Yes (y) or No (n)	" "\n\n";
	}
	return (yesno);
	{
	if (results <= 59)
	grade = 'F';
	if (results <= 69 && results >= 60)
	grade = 'D';
	if (results <= 79 && results >= 70)
	grade = 'C';
	if (results <= 89 && results >= 80)
	grade = 'B';
	if (results >= 90 && results <= 100)
	grade = 'A';
 }
	cout << "Your Grade is " << grade << "\n\n";
}

system ("pause");
return 0;
}





Please someone help.

MV*/

Is This A Good Question/Topic? 0
  • +

Replies To: Visual C++ Error system problem

#2 bsaunders  Icon User is offline

  • D.I.C Addict

Reputation: 44
  • View blog
  • Posts: 571
  • Joined: 18-January 09

Re: Visual C++ Error system problem

Posted 04 March 2009 - 12:02 AM

I see you're using a do-while statement in your program, but where is the while condition tested?

This post has been edited by bsaunders: 04 March 2009 - 12:03 AM

Was This Post Helpful? 0
  • +
  • -

#3 n8wxs  Icon User is offline

  • --... ...-- -.. . -. ---.. .-- -..- ...
  • member icon

Reputation: 972
  • View blog
  • Posts: 3,878
  • Joined: 07-January 08

Re: Visual C++ Error system problem

Posted 04 March 2009 - 12:12 AM

Picking up on bsaunders point you are missing the while() here:
...
		cout << "Your Grade is " << grade << "\n\n";
	} while();	 <<<<<<<<<<<<<<

 	system("pause");
	return 0;


I think you need to get the user's answer here
		default:
			cout << "Please enter Yes (y) or No (n)	" << "\n\n";


to test in the while() statement.

Earlier in the code you have return (yesno);. The grade assignment if statements will never execute.

This post has been edited by n8wxs: 04 March 2009 - 12:12 AM

Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,605
  • Joined: 23-August 08

Re: Visual C++ Error system problem

Posted 04 March 2009 - 05:11 AM

And the system() function requires the cstdlib header.
Was This Post Helpful? 0
  • +
  • -

#5 mvalor  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 16-November 08

Re: Visual C++ Error system problem

Posted 04 March 2009 - 10:07 PM

:D I want to thank all of you that helped me wise up. What was I thinking of???? (Slap my forehead please!)
I used the examples that you nice folks gave me and some of them were not necesarry for the end result, however it did teach me a little more about "do-while loops" and for this I am grateful.

Here is my code on the project I was working on:

# include <iostream>
# include <cmath>  //I was not sure that I would use this so I put it in anyway.
# include <cstdlib>

using namespace std;
int main()
{
//Declaring Values
char yesno;		 // did the user enter yes or no?
char choice;		// did the user enter yes or no?
float score;		// number grade
float x;			// Extra Credits
char grade;			// letter grade
float results;		// Final Score results

//Making the Grade
	cout  << "Enter a grade between 0 and 100:	" <<"\n";
	cin >> score;
	cout << "Are you sure this is the right score? Yes (y) or No (n)" <<"\n";
	cin >> yesno;
	cout << "\n\n";
	switch (yesno){
	case 'y': 
		cout<< score;
		cout << "\n\n";
		break;
	case 'n':
		score = 0;
		cout << "Please re-enter student score"   <<"\n";
cin >> score;
		break;
	}

// Extra Credit or not extra credit...that is the question.
//Getting Extra Credit (Choice)
	cout << "Is the student eligible for extra credit?"	<<"\n";
	cout << "Please enter Yes (y) or No (n)	" << "\n\n";
	cin >> choice;
	cout << "\n\n";
	
	switch (choice){
	case 'y': 
	cout << "Enter Extra Credits:	" <<"\n";
	cin >> x;
	cout << "Extra Credit:" << x	  <<"\n";
	results = (score + x);
	break;
	case 'n': 
	cout << "No extra credit entered. \n";
	results = (score + 0);
	break;
	}
	//Grading Format: as stated above.
	{
	if (results <= 59)
	grade = 'F';
	if (results <= 69 && results >= 60)
	grade = 'D';
	if (results <= 79 && results >= 70)
	grade = 'C';
	if (results <= 89 && results >= 80)
	grade = 'B';
	if (results >= 90 && results <= 100)
	grade = 'A';
 }
	//Grading Results
	cout << " Score:" <<results << "\n";
	cout << "Your Grade is " << grade << "\n\n";
system ("pause");
return 0;
}

//End of program




I would like to know how my real first Visual C++ program worked.

Please let me know

MV*/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1