# Thread: Calculator program problemo

1. ## Calculator program problemo

Code:
```#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <iostream>
using namespace std;

float Squareroot(float x);
float Add(float x, float y);
float Subtract(float x, float y);
float Multiply(float x, float y);
float Divide(float x, float y);

int main() {

cout << "Math Program v.1.8" << endl;

float numberA;
float numberB;
cout << "What two numbers would you like to input?" << endl;
cin >> numberA;
cin >> numberB;

cout << "Would you like to: \n" ;
cout << "Square[r]oot?" << endl;
cout << "[a]dd" << endl;
cout << "[s]ubtract" << endl;
cout << "[m]ultiply" << endl;
cout << "or [d]ivide the numbers?" << endl;

float funcvarbname;

string Option;
if (Option == "r") {funcvarbname=Squareroot(numberA);};
if (Option == "a") {funcvarbname=Add(numberA, numberB);};
if (Option == "s") {funcvarbname=Subtract(numberA, numberB);};
if (Option == "m") {funcvarbname=Multiply(numberA, numberB);};
if (Option == "d") {funcvarbname=Divide(numberA, numberB);};

cout << funcvarbname << endl;

system("PAUSE");
return 0;
}```
Well I fixed my original error, but now it doesn't print the answers to my functions! Help please!

2. it doesn't print the answers to my functions!
Um, isnt that because you arent printing anything with say, cout?

3. I was using cout. But anyway I fixed it:

Code:
```#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <iostream>
using namespace std;

float Squareroot(float x);
float Add(float x, float y);
float Subtract(float x, float y);
float Multiply(float x, float y);
float Divide(float x, float y);

int main() {

cout << "Math Program v.1.8" << endl;

float numberA;
float numberB;
cout << "What two numbers would you like to input?" << endl;
cin >> numberA;
cin >> numberB;

cout << "Would you like to: \n" ;
cout << "Square[r]oot?" << endl;
cout << "[a]dd" << endl;
cout << "[s]ubtract" << endl;
cout << "[m]ultiply" << endl;
cout << "or [d]ivide the numbers?" << endl;

float funcvarbname;

string Option;
cin >> Option;

if (Option == "r") {funcvarbname=Squareroot(numberA);};
if (Option == "a") {funcvarbname=Add(numberA, numberB);};
if (Option == "s") {funcvarbname=Subtract(numberA, numberB);};
if (Option == "m") {funcvarbname=Multiply(numberA, numberB);};
if (Option == "d") {funcvarbname=Divide(numberA, numberB);};

cout << "YOUR ANSWER IS: " << funcvarbname << endl;

system("PAUSE");
return 0;
}

float Squareroot(float x) {
return sqrt(x);
}
float Add(float x, float y) {
return x+y;
}
float Subtract(float x, float y) {
return x - y;
}
float Multiply(float x, float y) {
return x*y;
}
float Divide(float x, float y) {
return x / y ;
}```

4. I was using cout.
You forgot to use it to print what you wanted to print though, glad to see that you have it fixed.

Popular pages Recent additions