View Single Post
Old 12-10-2010, 04:38 PM   #1
Fubb
GreatCanadianMan
 
Fubb's Avatar


 
Join Date: May 2008
Location: Swan River, Canada
Posts: 842
Default C++ Calculator Problem

Now im not quite sure WHY this isn't working, but on the bolded line, my code finds and error and doesn't want to build

Quote:
#include <iostream>
using namespace std;

int main(void)
{

system("TITLE Calculator");
system("COLOR 2");
char cChar; // char is a character, its how you get plus and minus signs, etc //
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 want to complete"
<< " (+,-,*, or /)" << endl;
cin >> cChar;

}







{

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 * dsecondnumber)
<< endl;
break;
case 'X':
cout << "The answer is: " << dfirstnumber << " X " <<
dsecondnumber << " = " << (dfirstnumber * dsecondnumber)
<< endl;
break;
case '/':
if(dsecondnumber == 0) {
cout << "that is an invalid operation" << endl;
}else{
cout << "The answer is: " << dfirstnumber << " / " <<
dsecondnumber << " = " << (dfirstnumber / dsecondnumber)
<< endl;
}
break;
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");




/*system("pause") causes the program to stay open, but isnt necesary */
/* in programs like visual basic, */
/*int main(void) initialises main coding section*/
/*Two types of number variables, one is an integer or int, and one is a double*/
/*The integer deals with full numbers while the double deals with decimals */
/* d needs to be in front of dnumber because the d is a variable for double */
/* you must have 0.0 as your opening numbers or else it will not work properly */
Ignore the comments at the end. at the function opening bracket on the line before switch (cChar) is keeps giving me an error, any ideas?
__________________
Kugarfang: o hai guiz im trying to find this techno song from the radio and it goes like this:

DUN duuuunnnn dudududududun SPLOOSH duuunnnnn


We ate the horse.
Fubb is offline                         Send a private message to Fubb
Reply With Quote