college needs help again...ya diggg
Does anyone see whats wrong with the code
Hey im back everyone
Really need some help or rather some hints
Last time i was stressing over something that was very simple .
Everyone on the site seems so nice and im loving it.
Need help ...i need help please pretty please
Code:
#include<iostream>
using namespace std;
int main(void)
{
system("TITLE Calculator")
char cChar;
double dfirstnumber;
double dsecondnumber;
char cDoagain;
do
(
system("CLS");
cout <<"please enter the first number you would like to use"
<< endl;
cin >> dfirstnumber;
cout << " please enter the operation that you would liek to complete"
<< " (+,-,* or /)" << endl;
cin >> cChar;
cout << " please enter the second number you would like to use"
<< endl;
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 statr again ? ( y or n ) "
<< endl
cin >> cDoagain;
)while( cDoagain == " Y " || cdoagain == "y");
system (" PAUSE")
return 0;
}
There's one simple problem that I saw right away
With a switch statement, you can only use integers, not characters. So, for the operators, try giving them a number value, having your users type that number to perform the operation, and then keep using that number. Or, another thing you could do is use if...then...else statements. I only took a quick glance at it though, so there may be other things wrong with your code, but that should help (I remember making the same mistake doing the same thing, so I recognized it easily).