emulators

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
#include <iostream>

using namespace std;

template <class T>
long int funnyfunc(T val1, T val2, T val3);
void testvalue(int value, short unsigned int code);
void drawmenu(void);

int main(void)
{
	double num1, num2,num3;
	short unsigned int choice = 0; 
	while(choice!=4)
	{
		cout<<"please select from the following menu ";
		drawmenu();
		cin>>choice;
		try
		{
			testvalue(choice, 3);
			break;
		}

		catch (char* eString)
		{
			cout<< eString <<endl;
			cout<<" please re enter your menu choice ";
		}
	}

	if (choice == 4) 
	{
		cout <<"the program is over";
	}
	else
	{
		cout<<"please enter your first numeber ";
		cin>>num1;
		cout<<"please enter your second numeber ";
		cin>>num2;
		cout<<"please enter your third numeber ";
		cin>>num3;
	}
	enum BITOPS {INTEGER = 1, FLOAT, DOUBLE};
	BITOPS myOps = INTEGER;

	myOps  = BITOPS(choice);
	switch(myOps)
	{
	case INTEGER:
		cout<<"the result of interger type value is " <<funnyfunc(num1, num2, num3)<<endl;
		break;
	case FLOAT:
		cout<<"the result of float type value is " <<funnyfunc(num1, num2, num3)<<endl;
		break;
	case DOUBLE:
		cout<<"the result of double type value is " <<funnyfunc(num1, num2, num3)<<endl;
		break;

	default:
		cout<<"thank you for using !"<<endl;
	}

}

template <class T>
long int funnyfunc(T val1, T val2, T val3)
{
	return ((val1+val2)*val3);
}

void testvalue(int value, short unsigned int code)

{
	switch(code)
	{
	case 1:
		if(value < 0 )
			throw "error - value cannot be negative \n";
			break;
	case 2:
		if(value==0)
			throw "error you can't divided by zero \n";
		break;
	case 3:
		if (value < 1|| value > 4)
			throw "error - invalid menu selection";
		break;
	default:
		cout<<" unhandled exception";
		cout<<"program will stop";
		exit(1);
	}
}

void drawmenu(void)
{
	cout<<endl<<"\t1 - interger"<<endl;
	cout<<"\t2 - float" <<endl;
	cout<<"\t3 - double"<<endl;
	cout<<"\t4 - end this program";
}


1) Look at the code above, from what it saids it's saying choose either you will input int, double, float, and it will return the sum of first 2 number multiply by the third number. However, no matter how i see it, the answer will return an int. Am i correct?

2) Another question: why line 45 INTERGER = 1?

3) if i am wrong about my observation on 1), then where does the code recognize the input is int, double, float. Does it have something to do with line 45?

Topic archived. No new replies allowed.