-
January 20th, 2013, 07:53 PM
#1
My calculator program keeps crashing at the end
Hi all
I'm new to C++ and i decided to make a calculator with my limited knowledge. It works and all but it keeps crashing when it finishes. Anyone have an explanation/solution?
Here's my source code:
#include <iostream>
#include <string>
using namespace std;
class CALCULATIONS{
public:
int enterA(){
cin >> a;
}
int enterB(){
cin >> b;
}
int showA(){
cout << a;
}
string addA(){
if(b=="+"){
cout << "\n" << "Nice, what are you adding " << a << " by?\n\n";
cin >> c;
cout << "\n" << "I think it's " << a+c << endl;
cout << "Ima stop working now for no reason ";
}
else
subtractA();
}
string subtractA(){
if(b=="-"){
cout << "\n" << "Nice, what are you subtracting " << a << " by?\n\n";
cin >> c;
cout << "\n" << "I think it's " << a-c << endl;
cout << "Ima stop working now for no reason ";
}
else
multiplyA();
}
string multiplyA(){
if(b=="*"){
cout << "\n" << "Nice, what are you multiplying " << a << " by?\n\n";
cin >> c;
cout << "\n" << "I think it's " << a*c << endl;
cout << "Ima stop working now for no reason ";
}
else
divideA();
}
string divideA(){
if(b=="/"){
cout << "\n" << "Nice, what are you dividing " << a << " by?\n\n";
cin >> c;
cout << "\n" << "I think it's " << a/c << endl;
cout << "Ima stop working now for no reason ";
}
else
addA();
}
private:
int a;
string b;
int c;
};
int main()
{
CALCULATIONS caLc;
cout << "Hi, I'm a calculator ^_^\n\n\nEnter a number and press enter please... \n\n";
caLc.enterA();
cout << "\n" << "Cool, now what do you want to do with ";
caLc.showA();
cout << "?\n\n" << "(+) Add ?\n" << "(-) Subtract ?\n" << "(*) Multiply ?\n" << "(/) Divide ?\n\n";
caLc.enterB();
caLc.addA();
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|