u-noob-tu
May 17th, 2011, 05:04 PM
so ive been teaching myself C++ for about 2 1/2 months now, mostly through free online tutorials, and a book or two. one example i found was to make a program that multiplies two numbers. i got that to work just fine, but in order to get better i like to add on to the examples i find by combining them. this time, im trying to make a program that adds, subtracts, divides and multiplies two numbers (i dont know how to make it work with more than two at this point). i think im pretty close to getting it to work, but each time i run it, it only adds the numbers, even if i tell it to do otherwise. not getting any errors, so i think im missing a semicolon somewhere. heres the source code:
#include <iostream>
#include <string>
using namespace std;
int mult (int x, int y);
int main()
{
string answer;
int x;
int y;
cout << "Give me two numbers: ";
cin >> x >> y;
cin.ignore();
cout << "Do you want to add, multiply, subtract, or divide?\n";
cin >> answer;
cin.ignore();
if ((answer == "Add"));
{
cout << "These two numbers equal "<< x+y <<".\n";
}
int mult (int x, int y);
{
return x+y;
}
if ((answer == "Multiply"));
{
cout << "These two numbers equal "<< x*y <<".\n";
}
int mult (int x, int y);
{
return x*y;
}
if ((answer == "Subtract"));
{
cout << "These two numbers equal "<< x-y <<".\n";
}
int mult (int x, int y);
{
return x-y;
}
if ((answer == "Divide"));
{
cout << "These two numbers equal "<< x/y <<".\n";
}
int mult (int x, int y);
{
return x/y;
}
}
again, im just a beginner, and my resources to teach myself are limited. any help would be much appreciated.
#include <iostream>
#include <string>
using namespace std;
int mult (int x, int y);
int main()
{
string answer;
int x;
int y;
cout << "Give me two numbers: ";
cin >> x >> y;
cin.ignore();
cout << "Do you want to add, multiply, subtract, or divide?\n";
cin >> answer;
cin.ignore();
if ((answer == "Add"));
{
cout << "These two numbers equal "<< x+y <<".\n";
}
int mult (int x, int y);
{
return x+y;
}
if ((answer == "Multiply"));
{
cout << "These two numbers equal "<< x*y <<".\n";
}
int mult (int x, int y);
{
return x*y;
}
if ((answer == "Subtract"));
{
cout << "These two numbers equal "<< x-y <<".\n";
}
int mult (int x, int y);
{
return x-y;
}
if ((answer == "Divide"));
{
cout << "These two numbers equal "<< x/y <<".\n";
}
int mult (int x, int y);
{
return x/y;
}
}
again, im just a beginner, and my resources to teach myself are limited. any help would be much appreciated.