3 Replies - 442 Views - Last Post: 14 March 2010 - 12:52 PM Rate Topic: -----

#1 Guest_anon*


Reputation:

What is wrong with this code?

Posted 14 March 2010 - 12:43 PM

keep getting a compiler error fatal error C1075: end of file found before the left brace '{' at line (42)..there is no line 42....

#include "stdafx.h"
#include <iostream>
#include <math.h>


using namespace std;


int main ()

{

	int num1 ;
	int num2 ;
	char userinput;
	  
cout << "Welcome! please ENTER  'X' for mulptiplication , 'D' for division , 'A' for addition and 'S' for subtraction"<< endl ;
cin >> userinput ;
{
switch (userinput)
{
case 'X' :
	{
          cin >> num1 ;
		  cin >> num2 ;
		 cout <<num1<< "X"<<num2<<"="<<num1 * num2 <<endl;
             break ;
	
case 'D' :
	{
		cin >> num1;
		cin >> num2 ;
		cout <<num1<<"/"<<num2<< "="<<num1/num2<<endl;
		break ;
	}
		system("PAUSE");
		return 0 ;
	}



Is This A Good Question/Topic? 0

Replies To: What is wrong with this code?

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1637
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: What is wrong with this code?

Posted 14 March 2010 - 12:49 PM

It looks as if you just started throwing braces all over the place, without even thinking of where you need them and where you dont.

Here's your code the way it's supposed to look

#include "stdafx.h"
#include <iostream>
#include <math.h>


using namespace std;


int main ()
{

	int num1 ;
	int num2 ;
	char userinput;

	cout << "Welcome! please ENTER  'X' for mulptiplication , 'D' for division , 'A' for addition and 'S' for subtraction"<< endl ;
	cin >> userinput ;

		switch (userinput)
		{
			case 'X' :
					cin >> num1 ;
					cin >> num2 ;
					cout <<num1<< "X"<<num2<<"="<<num1 * num2 <<endl;
					break ;

			case 'D' :
					cin >> num1;
					cin >> num2 ;
					cout <<num1<<"/"<<num2<< "="<<num1/num2<<endl;
					break ;
				system("PAUSE");
				return 0 ;
		}
}


Was This Post Helpful? 0
  • +
  • -

#3 adgarci  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 96
  • Joined: 26-August 09

Re: What is wrong with this code?

Posted 14 March 2010 - 12:51 PM

Wrong placement of the brackets, each case doesn't need them.

EDIT: Ninja'd by PsycoCoder

This post has been edited by adgarci: 14 March 2010 - 12:52 PM

Was This Post Helpful? 1
  • +
  • -

#4 Guest_anon*


Reputation:

Re: What is wrong with this code?

Posted 14 March 2010 - 12:52 PM

THANKS!
Was This Post Helpful? 0

Page 1 of 1