This program doesn't run because some problem with the reduce fraction.
My reduce fraction is all right but when I tried to put that in this program, It has some errors.
Or maybe the switch menu is wrong? because I put another swith menu in the main switch menu.
I guess the problem is In the division - fraction section
the error says something like cases are skipped by something.. I don't remember because I only get the chances to use C++ in the class
Thanks guys! I appreciate it.
1) Addition
2) Subtraction
3) Multiplication
4) Division
a) answer as a decimal
b) answer as a fraction
c) answer as a number with a remainder
5) Multiplication by a percent (i.e. 10 times 20% equals 2)
6) Calculate powers. (i.e. 23=8)
7) Be able to figure out the area of a circle because you have PI=3.14159 on your calculator
8) Calculate an exponential (i.e. 8 x 103 = 8e3)
- //Claire's Calculator
-
#include <iostream.h>
-
#include <math.h>
-
double pow(double x, double y);
-
-
-
main()
-
{
-
int choice, choicee;
-
const double PI = 3.14159;
-
float a, b, c;
-
int n, m;
-
double cy;
-
double x, y;
-
float x_to_the_y;
-
double r;
-
int re, q;
-
-
do //
-
{
-
cout << "Which calculation you wish to use?" << '\n';
-
cout << "1 - Addition" << '\n';
-
cout << "2 - Subtraction" << '\n';
-
cout << "3 - Multiplication" << '\n';
-
cout << "4 - Division " << '\n';
-
cout << "5 - Multiplication by a percent " << '\n';
-
cout << "6 - Calculate powers" << '\n';
-
cout << "7 - Calculate a circle" << '\n';
-
cout << "8 - Calculate an exponential" << '\n';
-
cin >> choice; //get choice from the user
-
if ((choice < 1 ) || (choice > 8))
-
{
-
cout << "Re-enter your choice.\n";
-
}
-
}
-
while ((choice < 1 ) || (choice > 8));
-
-
switch(choice)
-
{
-
case 1: // Addition
-
cout << "enter 1st number: \n";
-
cin >> a;
-
cout << "enter 2nd number: \n";
-
cin >> b;
-
cout << "a + b =" << a + b << '\n';
-
break;
-
case 2: //Subtraction
-
cout << "Enter first number: \n";
-
cin >> a;
-
cout << "Enter second number: \n";
-
cin >> b;
-
cout << "a - b = " << a - b << '\n';
-
break;
-
case 3: //Multiplication
-
cout << "Enter first number: \n";
-
cin >> a;
-
cout << "Enter second number: \n";
-
cin >> b;
-
cout << "a * b = " << a * b << '\n';
-
break;
-
case 4: //Division
-
do {
-
cout << "1 - answer as a decimal\n";
-
cout << "2 - answer as a fraction\n";
-
cout << "3 - answer as a number with a remainder\n";
-
cin >> choicee;
-
}
-
while ((choicee < 1 ) || (choicee > 3));
-
-
switch(choicee)
-
{
-
case 1: //answer as a decimal
-
cout << "Enter first number: \n";
-
cin >> a;
-
cout << "Enter second number: \n";
-
cin >> b;
-
cy = a / b;
-
cout << "answer = " << cy << '\n';
-
break;
- case 2: //answer as a fraction
-
int n, m, i = 0;
-
int Denom, Num;
-
cout << "Enter first number: \n";
-
cin >> n;
-
cout << "Enter second number: \n";
-
cin >> m;
-
n = Denom;
-
m = Num;
-
for (i = n * m; i > 1; i--)
-
{
-
if ((n % i == 0) && (m % i == 0))
-
{
-
n /= i;
-
m /= i;
-
}
-
}
-
cout << "a=" << n << "/" << m << '\n';
-
-
break;
-
case 3: //answer as a number with a remainder
-
cout << "Enter first number: \n";
-
cin >> a;
-
cout << "Enter second number: \n";
-
cin >> b;
-
q = a / b;
-
re = (int)a % (int)b;
-
cout << "quotient = " << q << '\n';
-
cout << "reminder = " << re << '\n';
-
}
-
-
case 5: //Multiplication by a percent
-
cout << "Enter first number: \n";
-
cin >> a;
-
cout << "Enter second number:(percentage) \n";
-
cin >> b;
-
c = a * (b / 100);
-
cout << "answer = " << c << '\n';
-
break;
-
case 6: //Calculate powers
-
double pow(double x, double y);
-
cout << "Enter first number: \n";
-
cin >> x;
-
cout << "Enter the power: \n";
-
cin >> y;
-
x_to_the_y = pow(x, y);
-
cout << "answer = " << x_to_the_y << '\n';
-
break;
-
case 7: //Calculate a circle
-
cout << "Please enter r = \n";
-
cin >> r;
-
cout << "The area is " << PI * r * r << '\n';
-
break;
-
case 8: // Calculate an exponential
-
cout << "Enter first number: \n";
-
cin >> a;
-
double pow(double x, double y);
-
cout << "Enter second number: \n";
-
cin >> x;
-
cout << "Enter the power: \n";
-
cin >> y;
-
x_to_the_y = pow(x, y);
-
cout << "answer = " << a * x_to_the_y << '\n';
-
break;
-
}
-
return 0;
-
}