# Calculator program problemo

• 09-04-2005
blankstare77
Calculator program problemo
Code:

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

float Squareroot(float x);
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!
• 09-04-2005
laserlight
Quote:

it doesn't print the answers to my functions!
Um, isnt that because you arent printing anything with say, cout?
• 09-04-2005
blankstare77
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 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);};

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 ;
}

• 09-04-2005
laserlight
Quote:

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.