This is my second program in c++ so im kind of new. Ive used the code below but i get quite a few errors. There was one that said "case label does not reduce to an integer constant" and i got no idea what to do. If someone could look at my code and tell me where i went wrong, and tell me if i might recieve more errors later on it would be greatly appreciated. Thanks, Heres the code:
include <iostream>
using namespace std;
int main(void)
{
system ("TITLE Calculator");
char cchar;
double dnumber1;
double dnumber2;
char cdoagain;
do{system("CLS");cout<<"PleaseEnteryourFirstNumber"<<endl;cin>>dnumber1;cout<<endl;cout<<"Pleasetypetheoperationyouwouldliketouse"<<endl;cout<<"+,-,x,/"<<endl;cin>>cchar;cout<<endl<<"PleaseEntertheSecondNumberyouwouldliketouse"<<endl;cin>>dnumber2;switch(cchar){case"+";// THIS LINE IS HIGHLIGHTED WITH ERROR SIGNcout<<dnumber1<<"+"<<dnumber2<<"="<<(dnumber1+dnumber2)<<endl;break;case"-";cout<<dnumber1<<"-"<<dnumber2<<"="<<(dnumber1-dnumber2)<<endl;break;case"x";cout<<dnumber1<<"x"<<dnumber2<<"="<<(dnumber1*dnumber2)<<endl;break;case"X";cout<<dnumber1<<"x"<<dnumber2<<"="<<(dnumber1*dnumber2)<<endl;break;case"*";cout<<dnumber1<<"*"<<dnumber2<<"="<<(dnumber1*dnumber2)<<endl;break;case"/";if(dnumber2==0){cout<<"Thisisaninvalidoperation"<<endl;}
cout<< "Would you like to start again? (y/n)" <<endl;cin>> cdoagain;while(cdoagain=="y" || cdoagain == "Y");system("PAUSE");return0;}
}
you use the " " with string literals as in std::string name = "Bob";
you use the ' ' when dealing with character constants as in char letter = 'a' etc,
the '+' '-' etc are character constants,ie they never change.
I heard over at sourceforge pdCurses forum that using system( 'input command here' ) causes big overhead,
probably better off using the standard cout or c's printf?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is my second program in c++ so im kind of new. Ive used the code below but i get quite a few errors. There was one that said "case label does not reduce to an integer constant" and i got no idea what to do. If someone could look at my code and tell me where i went wrong, and tell me if i might recieve more errors later on it would be greatly appreciated. Thanks, Heres the code:
include <iostream>
using namespace std;
int main(void)
{
system ("TITLE Calculator");
char cchar;
double dnumber1;
double dnumber2;
char cdoagain;
else {
cout << dnumber1 << " / " << dnumber2 << " = " << (dnumber1 / dnumber2) <<endl;
}
break;
default;
cout << "That is an Invalid Operation!" <<endl;
break;
=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
you use the " " with string literals as in std::string name = "Bob";
you use the ' ' when dealing with character constants as in char letter = 'a' etc,
the '+' '-' etc are character constants,ie they never change.
I heard over at sourceforge pdCurses forum that using system( 'input command here' ) causes big overhead,
probably better off using the standard cout or c's printf?