Go Back   Forums > Community Chatterbox > Tech Corner > Programming
Memberlist Forum Rules Today's Posts
Search Forums:
Click here to use Advanced Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with XP SkiFree Troubleshooting 4 16-03-2010 02:42 PM
I Have A Problem! kevinitzac General compatibility fixes 1 22-04-2007 03:49 PM
Problem Dark Piedone Tech Corner 12 02-01-2006 07:22 PM
Dos Box Problem lost guy Troubleshooting 1 10-12-2004 09:14 AM
Dos Problem Anonymous Troubleshooting 13 25-09-2004 02:08 AM


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump
 


The current time is 08:08 PM (GMT)

 
Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.