Suggestions

Hello, I have already posted this in the beginner forums, but I thought I might as well post here as well. I have but recently written a program that uses some mathematic equations, and I was wondering if any one had some suggestions or thoughts on it, that would be great. Thanks.

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

int main()
{

double A, B, D;
char C, T, P;
for (;;) {
do {


cout << "\t\t\tGANTOR 82.1 Math Program\n\n\n";


cout << "\t\n\nWelcome, to GANTOR's Math program, what would you like to do?\n\n";
cout << "\t1. Solve with calculator\n";
cout << "\t2. Solve with Pythagorean's Theorem\n";
cout << "\t3. Quit\n";
cout << "\nEnter your number here: ";
cin >> C;
} while ( C < '1' || C > '7' && C != 'Q');
if (C == '3') break;

switch (C) {
case '1':
system ("CLS");
cout << "\t\t\tWelcome to the calculator portion\n\n\n";
cout << "\t\tSelect the operator you would like to use";
cout << "\n\nA. Addition" << endl;
cout << "\nB. Subtraction" << endl;
cout << "\nC. Division" << endl;
cout << "\nD. Multiplication" << endl;
cout << "\nE. Quit (press Q)" << endl;
cout << "\nEnter your letter here: ";
cin >> T;
if (C == 'Q') break;
switch (T) {
case 'A':

cout << "\nPlease enter a number: ";
cin >> A;
cout<<"Enter another number to be added: ";
cin >> B;
cout << A + B;
cout << "\n";
system ("PAUSE");
system ("CLS");
break;






case 'B':
cout << "\nPlease enter a number you would like to subtract from: ";
cin >> A;
cout << "Enter the number you would like to subtract from the first number: ";
cin >> B;
cout << A - B;
cout << "\n";
system ("PAUSE");
system ("CLS");
break;


case 'C':
cout << "\nPlease enter the numerator: ";
cin >> A;
cout << "Enter the denominator: ";
cin >> B;
cout << A / B;
cout << "\n";
system ("PAUSE");
system ("CLS");
break;

case 'D':
cout << "\nPlease enter a number: ";
cin >> A;
cout << "Enter another number to be multiplied: ";
cin >> B;
cout << A * B;
cout << "\n";
system ("PAUSE");
system ("CLS");
break;
}
return 0;




case '2':

system ("CLS");
cout << "\t\tWelcome to the Pythagorean Theorem portion\n\n\n";
cout << "\t\tThe equation is, as you know, (a2 + b2 = c2)\n\n";
cout << "\tPlease enter the variable you would like to solve for\n\n";
cout << "\n\t\ta\n\n";
cout << "\n\t\tb\n\n";
cout << "\n\t\tc\n\n";
cout << "\tEnter your side here: ";
cin >> C;
switch (C) {
case 'a':
cout << "\n\nPlease enter b's value: ";
cin >> A;
cout << "\n\nEnter c's value: ";
cin >> B;
// solve the equation here
cout << (B * B) - (A * A);
// print the answer
cout << " to the 2nd\n\n";
system ("PAUSE");
system ("CLS");
break;
case 'b':
cout << "\n\nPlease enter a's value: ";
cin >> A;
cout << "\n\nEnter c's value: ";
cin >> B;
// solve the equation here
cout << (A * A) - (B * B);
// print the answer
cout << " to the 2nd\n\n";
system ("PAUSE");
system ("CLS");
break;
case 'c':
cout << "\n\nPlease enter a's value: ";
cin >> A;
cout << "\n\nEnter b's value: ";
cin >> B;
cout << (A * A) + (B * B);
cout << " to the 2nd\n\n";
system ("PAUSE");
system ("CLS");
break;



}
return 0;


}
}
return 0;
}


cout << "\nE. Quit (press Q)" << endl;

you are just checking Q, but someone can press E also. because this is also an option.
your do while looks complicated..

you should have your switch in while, that will make it quite clear. like this:

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
while(1)
{
//take option here
cout << "\t1. Solve with calculator\n";
cout << "\t2. Solve with Pythagorean's Theorem\n";
cout << "\t3. Quit\n";
cout << "\nEnter your number here: ";
cin >> C;
switch (C) {
case 1:
//do some work
break;

case 2:
//do some work
break;

case 3:
return 0;
break;

default:
cout << "invalid option, try again please." << endl;
break;
}
}


at least tell user that he is entering some wrong choice. your loop will keep on taking inputs from user but he will never know whats wrong is going on.
Topic archived. No new replies allowed.