forked from mostafa-saad/ArabicCompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path08 C++ Programming 4 Competitions - Practice - Calculator V1.0.cpp
87 lines (72 loc) · 2.02 KB
/
08 C++ Programming 4 Competitions - Practice - Calculator V1.0.cpp
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
//============================================================================
// Name : CompetitiveSeries.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
int main()
{
// Main Variables: Declare + Initialize
double dNum1 = 0; // d for double. Num N capital for camelCasing
double dNum2 = 0;
double dResult = 0;
int iChoice = 0;
cout<<"\t\t\t\t*** Welcome to our Calculator V1 ***\n\n\n\n";
CalculatorStartingPoint: //goto point re back here
cout<<"Please Enter 2 numbers: ";
cin>>dNum1>>dNum2;
// Input Validation
if (cin.fail())
{
cout<<"You should enter correct values\n\n";
cin.clear();
cin.ignore(10000, '\n');
goto CalculatorStartingPoint;
}
MenuStartingPoint:
// Display the menu
cout<<"\nMenu Options:\n";
cout<<"\tTo sum the numbers enter 1\n";
cout<<"\tTo subtract the numbers enter 2\n";
cout<<"\tTo multiply the numbers enter 3\n";
cout<<"\tTo divide the numbers enter 4\n";
cout<<"\tTo enter the 2 numbers again, enter 5\n";
cout<<"\n\tEnter the choice: ";
cin>>iChoice;
// Input Validation
if (cin.fail())
{
cout<<"\t\tYou should enter correct value\n\n";
cin.clear();
cin.ignore(10000, '\n');
goto MenuStartingPoint;
}
// Let check for the result
if (iChoice == 1)
dResult = dNum1 + dNum2;
else if (iChoice == 2)
dResult = dNum1 - dNum2;
else if (iChoice == 3)
dResult = dNum1 * dNum2;
else if (iChoice == 4)
{
if (dNum2 == 0.0)
{
cout<<"\t\tWe can't divide by zero. Retry other 2 numbers\n\n";
goto CalculatorStartingPoint;
}
dResult = dNum1 / dNum2;
}
else if (iChoice == 5)
goto CalculatorStartingPoint;
else
{
cout<<"\t\tChoice must be from 1 to 5. Retry again\n\n";
goto MenuStartingPoint;
}
cout<<"\nResult of operation: "<<dResult<<"\n";
return 0;
}