syntax?

This is a discussion on syntax? within the C++ Programming forums, part of the General Programming Boards category; ok so i have no idea what tags are i probably posted this wrong i have no idead what i ...

  1. #1
    Registered User arc_angel14's Avatar
    Join Date
    Sep 2010
    Location
    USA
    Posts
    18

    syntax?

    ok so i have no idea what tags are i probably posted this wrong

    i have no idead what i did wrong i know its probably simple but i have only been programming for a week




    Code:
    #include<iostream>
    using namespace std;
    
    int main(void)
    {
    
    	system("TITLE Calculator");
    	system("COLOR 2");
    	char cChar;
    	double dfirstnumber;
    	double dsecondnumber;
    	char cDoagain;
    	
    do
    {
    	system("CLS");
    	cout << "please enter the first number that you would like to use" << endl;
    	cin >> dfirstnumber;
    	cout << "please enter the operation that you would like to complete" << " (+,-,* or /)" << endl;
    	cin >> cChar;
    	cout << "please enter the second number you would like to use" << endl;
    	cin >> dsecondnumber;
    	
    		switch (cChar)
    		{
    		case '+':
    			cout << "the answer is; " << dfirstnumber << " + " << dsecondnumber << " = " << (dfirstnumber + dsecondnumber) << endl;
    				break;
    		case '-':
    			cout << "the answer is; " << dfirstnumber << " - " << dsecondnumber << " = " << (dfirstnumber - dsecondnumber) << endl;
    				break;
    		case '*':
    			cout << "the answer is; " << dfirstnumber << " * " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl;
    				break;
    		case 'x':
    			cout << "the answer is; " << dfirstnumber << " x " << dsecondnumber << " = " << (dfirstnumber x dsecondnumber) << endl;
    				break;
    		case 'X':
    			cout << "the answer is; " << dfirstnumber << " X " << dsecondnumber << " = " << (dfirstnumber X dsecondnumber) << endl;
    				break;
    		case '/':
    			if(dsecondnumber ==0) {
    			cout << "that is an invalid operation" << endl;
    			}else{
    			cout << "The answer is; " << dfirstnumber << " / " << dsecondnumber << " = " << (dfirstnumber / dsecondnumber) << endl;
    			}
    		default:
    			cout << "that is an invalid operation" << endl;
    			break;
    		}
    		cout << "would you like to start again? (y or n)" << endl;
    		cin >> cDoagain;
    	}while (cDoagain == 'Y' || cDoagain == 'y');
    	system("pause");
    	return 0;
    	
    }

  2. #2
    Registered User arc_angel14's Avatar
    Join Date
    Sep 2010
    Location
    USA
    Posts
    18
    these are the errors if it helps

    error C2146: syntax error : missing ')' before identifier 'x'
    error C2059: syntax error : ')'
    error C2146: syntax error : missing ')' before identifier 'X'
    error C2059: syntax error : ')'

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Well here is your error
    Code:
    (dfirstnumber x dsecondnumber)
    of course you want * instead of x.

    Next time double click on the error, usually it highlights the line it is on. Or look at the error message and go to that line. In any case, find the line where the error is. Then you should be able to figure it out more.

    Why do I say that? Because I was looking for 'x' and 'X' in your code. I first show the ones after case. So I checked those, but they were ok. Did you do the same? If yes, then you should have followed my advice above when running through an IDE with a compiler (I guess you are using Visual Studio?), since you could have found out which line it is on exactly. Which in case you would look on that line for 'x'. Which would lead you right on the problem!

  4. #4
    Registered User arc_angel14's Avatar
    Join Date
    Sep 2010
    Location
    USA
    Posts
    18
    Quote Originally Posted by C_ntua View Post
    Well here is your error
    Code:
    (dfirstnumber x dsecondnumber)
    of course you want * instead of x.

    Next time double click on the error, usually it highlights the line it is on. Or look at the error message and go to that line. In any case, find the line where the error is. Then you should be able to figure it out more.

    Why do I say that? Because I was looking for 'x' and 'X' in your code. I first show the ones after case. So I checked those, but they were ok. Did you do the same? If yes, then you should have followed my advice above when running through an IDE with a compiler (I guess you are using Visual Studio?), since you could have found out which line it is on exactly. Which in case you would look on that line for 'x'. Which would lead you right on the problem!
    i did that but the error said missin ) before x so i thought x was fine i thought it meant i was missing ) before it? but any ways so i should delete one line and cahnge the other to * ?

  5. #5
    Registered User arc_angel14's Avatar
    Join Date
    Sep 2010
    Location
    USA
    Posts
    18
    Quote Originally Posted by arc_angel14 View Post
    i did that but the error said missin ) before x so i thought x was fine i thought it meant i was missing ) before it? but any ways so i should delete one line and cahnge the other to * ?
    when i run and divide a number it always says this is an invalid operation while running it?
    i really new to programming like 2 days lol srry if it really stupid of me to ask

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 04:01 PM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 09:26 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21