Help please

Hello everyone, can someone help me and tell why my program wont give me a result, I know Im using the do while-loop because the program is suppose to continue until user decides to exit, but I dont know why I cant get the result to display

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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include<iomanip>

using namespace std;
char again;

void Values(double &num1, double &num2)
{
    
cout << "Please enter two numbers to calculate " << setprecision(5) << "\nNumber 1 "<<endl;
cin >> num1;
cout <<setprecision(5)<< "\nNumber 2 " <<endl;
cin >> num2;



}


        



void Addition(double &num1, double &num2, double &Result)	
{
Result = num1 + num2;
}

void Subtraction(double &num1, double &num2, double &Result)	
{
Result = num1 - num2;
}

void Multiplication(double &num1, double &num2, double &Result)	
{
Result= num1 * num2;
}

void Division(double &num1, double &num2, double &Result)		
{
	if(num2 != 0) 
		{
			setprecision(5);
			Result = num1 / num2;
		}
	else
		cout << "Please enter a number other than 0 as denominator"<<endl<<endl;
	
    
    
    
    	
}

 
 

int main()
{

char choice;
double num1,num2, Result;

do
{
Values(num1, num2);

cout << endl << endl << "Table of Operations" << endl;
cout << "A - Addition" << endl;
cout << "S - Subtraction" << endl;
cout << "M - Multiplication" << endl;
cout << "D - Division" << endl;
cout << "E - Exit" <<endl<<endl;
cout << "Enter choice for calculation: " ;
cin >> choice;
} while (choice != 'E');






switch(choice)	 // Switch function allows user to choose the calculation to execute
{
   case 'A':
   case 'a':
      Addition(num1, num2, Result);
      break;
   case 'S':
   case 's':
      Subtraction(num1, num2, Result);
      break;
   case 'M':
   case 'm':
      Multiplication(num1, num2, Result);
      break;
   case 'D':
   case 'd':
      Division(num1, num2, Result);
      break;
   default:
     case 'E':
     case'e':
          cout << "E - Exit Program" << endl << endl;
          exit(0); 
          
          
           
          cout << "Please enter a valid menu choice from above: ";
          cin >> choice;
          break;
        
        
        
        }





system("PAUSE");
return 0;
}
The program cannot read your mind, you have to tell it to display the value of Result.

Line 102 and 103 do no make sense inside that default case. Lines 109 - 111 belong with the default case and lines 104 and 105 belong with cases "E" and "e"

Lines 84 - 115 are supposed to be inside the do-while loop

EDIT: Do not double post http://www.cplusplus.com/forum/beginner/108052/
Last edited on
thanks, sorry I didnt I wasnt suppose to.

I was wondering why is it that when I input 0 for number 2 I get a display of "Please enter a number other than 0 as denominator result is 3"

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
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>
#include<iomanip>

using namespace std;

void Values(double &num1, double &num2)
{
cout << "Please enter two numbers to calculate; " << setprecision(5) << "\nNumber 1 " <<endl;
cin >> num1;
cout <<setprecision(5)<< "\nNumber 2 " <<endl;
cin >> num2;
}

void Addition(double &num1, double &num2, double &Result)	 // Function used to calculate sum
{
Result = num1 + num2;
}

void Subtraction(double &num1, double &num2, double &Result)	
{
Result = num1 - num2;
}

void Multiplication(double &num1, double &num2, double &Result)	
{
Result= num1 * num2;
}

void Division(double &num1, double &num2, double &Result)			// Function used to calculate quotient
{
	if(num2 != 0) 
		{
			setprecision(5);
			Result = num1 / num2;
		}
	else
		cout << "Please enter a number other than 0 as denominator";
		
}





int main()
{
char choice;

double num1,num2, Result;

do
{
Values(num1, num2);

cout << endl << endl << "Table of Operations" << endl;
cout << "A -- Addition" << endl;
cout << "B -- Subtraction" << endl;
cout << "C -- Multiplication" << endl;
cout << "D -- Division" << endl;
cout << "E -- Exit" <<endl<<endl;
cout << "Enter choice for calculation: " ;
cin >> choice;





switch(choice)	 // Switch function allows user to choose the calculation to execute
{
   case 'A':
   case 'a':
      Addition(num1, num2, Result);
      break;
   case 'B':
   case 'b':
      Subtraction(num1, num2, Result);
      break;
   case 'C':
   case 'c':
      Multiplication(num1, num2, Result);
      break;
   case 'D':
   case 'd':
      Division(num1, num2, Result);
      break;
   default:
     case 'E':
     case'e':
          cout << "E - Exit Program" << endl << endl;
          exit(0); 
      
}


{
      cout << "result is " << Result <<endl;
      }

} while (choice != 'E');
system("PAUSE");
return 0;
}



1
2
3
4
5
6
7
8
9
 case 'D':
   case 'd':
	         while(num2 == 0)
			 {
              cout << "Please enter a number other than 0 as denominator";
			  cin>>num2;
			 }
      Division(num1, num2, Result);
      break;


Remove if else statement in ur divison function.
Also u should prompt for choice of operation first, then ask for input.
Topic archived. No new replies allowed.