Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.
Moderator: Coders of Rage
Fallental
Chaos Rift Newbie
Posts: 43 Joined: Mon Mar 02, 2009 6:13 pm
Post
by Fallental » Tue Dec 15, 2009 9:37 pm
I get this error when debugging my program - (69) : error C2059: syntax error : '}'
(btw i think line 69 = last line)
Here is my code(new to programming)! please help! - written in c++ console
Code: Select all
#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 << "Enter your first number: " << endl;
cin >> dfirstnumber;
cout << "Enter the operation you want to complete: " << " (+,-,*, or /)" << endl;
cin >> cChar;
cout << "Enter your second number" << endl;
switch (cChar)
{
case '+':
cout << "Answer: " << dfirstnumber << " + " << dsecondnumber << " = " << (dfirstnumber + dsecondnumber) << endl;
break;
case '-':
cout << "Answer: " << dfirstnumber << " - " << dsecondnumber << " = " << (dfirstnumber - dsecondnumber) << endl;
break;
case '*':
cout << "Answer: " << dfirstnumber << " * " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl;
case 'X':
cout << "Answer: " << dfirstnumber << " X " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl;
case 'x':
cout << "Answer: " << dfirstnumber << " x " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl;
break;
case '/':
if(dsecondnumber == 0){
cout << " Invalid Operation! " << endl;
} else {
cout << "Answer: " << dfirstnumber << " / " << dsecondnumber << " = " << (dfirstnumber / dsecondnumber) << endl;
break;
}
break;
default:
cout << "Invalid Operation! " << endl;
break;
cout << "Would you like to reset? (Y/N)" << endl;
cin >> cDoagain;
}
{while (cDoagain == 'Y' || cDoagain == 'y');
system("Pause");
return 0;
}
}
}
Maknis
Chaos Rift Newbie
Posts: 2 Joined: Tue Dec 15, 2009 9:30 pm
Post
by Maknis » Tue Dec 15, 2009 10:00 pm
Hey there,
I am firstly going to say that i do not know 1 line of c++, have never studied it but i am more than likely wrong
but i can see this..
Code: Select all
cin >> cDoagain;
}
{while (cDoagain == 'Y' || cDoagain == 'y');
system("Pause");
return 0;
}
}
}
to me (again i don't know c++) you have an opening { infront of the while look
either this is not meant ot be there and if it is you haven't closed it
Fallental
Chaos Rift Newbie
Posts: 43 Joined: Mon Mar 02, 2009 6:13 pm
Post
by Fallental » Tue Dec 15, 2009 10:36 pm
hmmm thank you that was wrong too, but when i correct it even more errors pop up lawl
hurstshifter
ES Beta Backer
Posts: 713 Joined: Mon Jun 08, 2009 8:33 pm
Favorite Gaming Platforms: SNES
Programming Language of Choice: C/++
Location: Boston, MA
Contact:
Post
by hurstshifter » Tue Dec 15, 2009 10:40 pm
Do not place a semi-colon after the condition of your while loop...
GOOD
BAD
You also might want to think about organizing your code better. Proper indentation, white-space, and commenting will help others to understand your code.
Bakkon
Chaos Rift Junior
Posts: 384 Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana
Post
by Bakkon » Wed Dec 16, 2009 6:56 am
Hurst, that's a do-while loop. Semicolon after the while is correct syntax.
The problem is your curly braces are a mess. Hopefully I can list them all for you:
- one MISSING at the end of your switch
- one EXTRA on the same line as the while statement
- two EXTRA at the very end
I got this to compile. Hopefully this maintained your logic.
Code: Select all
#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 << "Enter your first number: " << endl;
cin >> dfirstnumber;
cout << "Enter the operation you want to complete: " << " (+,-,*, or /)" << endl;
cin >> cChar;
cout << "Enter your second number" << endl;
switch (cChar)
{
case '+':
cout << "Answer: " << dfirstnumber << " + " << dsecondnumber << " = " << (dfirstnumber + dsecondnumber) << endl;
break;
case '-':
cout << "Answer: " << dfirstnumber << " - " << dsecondnumber << " = " << (dfirstnumber - dsecondnumber) << endl;
break;
case '*':
cout << "Answer: " << dfirstnumber << " * " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl;
case 'X':
cout << "Answer: " << dfirstnumber << " X " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl;
case 'x':
cout << "Answer: " << dfirstnumber << " x " << dsecondnumber << " = " << (dfirstnumber * dsecondnumber) << endl;
break;
case '/':
if(dsecondnumber == 0)
{
cout << " Invalid Operation! " << endl;
}
else
{
cout << "Answer: " << dfirstnumber << " / " << dsecondnumber << " = " << (dfirstnumber / dsecondnumber) << endl;
break;
}
break;
default:
cout << "Invalid Operation! " << endl;
break;
}
cout << "Would you like to reset? (Y/N)" << endl;
cin >> cDoagain;
}
while (cDoagain == 'Y' || cDoagain == 'y');
system("Pause");
return 0;
}