1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
#include <iostream>
#include <string>
using namespace std;
// int x,y,result,c,d,e,f,g,h; //Move these to local scope
// char choice[10]; // NEVER use global if you don't have to
int subtraction (int a, int b)
{
//int r; Delete this
return a-b;
}
int addition (int c, int d)
{
// int s; Delete this
return c+d;
}
int multiplication (int e, int f)
{
// int t; Delete this
return e*f;
}
int devision (int g, int h)
{
// int u;Delete this
return g/h;
}
int main ()
{
// int x,y,result,c,d,e,f,g,h; You don't need all these I decaled what you do below
// char choice[10]; // Change to string
string choice;
int x, y;
int result;
cout<<"Would You Like To Add, Subtract, Multiply or Divide?"<< '\n';
cout<<"\n";
cout<<"Please Enter Add/Subtract/Multiply/Divide"<< '\n';
cout<<": ";
cin>>choice;
// Below here you had a lot of problems. One was using opening brackets before your
// If statements which should come after
// Another your use off all different variable to store info that you don't need
// I deleted all the variables except x and y (Which you were still using uninitilized)
if (choice == "Add")
{ // You had this before the if statement they come after
cout<<"Number 1: ";
// cin>>c; // Changed to x
cin >> x;
cout<<"\nNumber 2: ";
// cin>>d; // Changed to y
cin >> y;
result = addition (x,y);
cout<<"The Result Is: "<<result<<'\n';
}
else if (choice == "Subtract") // Changed to else if
{
cout<<"Number 1: ";
cin >> x;
cout<<"\nNumber 2: ";
cin >> y;
result = subtraction (x,y);
cout<<"The Result Is: "<<result<<'\n';
}
else if (choice == "Multiply") // Changed to else if
{
cout<<"Number 1: ";
cin >> x;
cout<<"\nNumber 2: ";
cin >> y;
result = multiplication (x,y);
cout<<"The Result Is: "<<result<<'\n';
}
else if (choice == "Divide") // Changed to else if
{
cout<<"Number 1: ";
cin >> x;
cout<<"\nNumber 2: ";
cin >> y;
result = devision (x,y);
cout<<"The Result Is: "<<result<<'\n';
}
return 0;
}
|