Efficient coding ?

Hey i recently made a small code to do some basic addition and multiplication . Can you guys point out how to improve the code.

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

using namespace std;

class add 
{
	int a , b;
	public:
		
	void getNum(int , int);
	
	int addition()
	{
		return a + b;
	}
	
};


    void add::getNum(int x, int y )
    {
    a = x;
	b = y;	
	}

class Multiplication
{
	int c , d;
	public:
		
	void getNum(int , int);
	
	int multiply()
	{
		return c * d;
	}
};
void Multiplication::getNum(int x, int y )
    {
    c = x;
	d = y;	
	}

	
	int main()
	{
		
		int x , y , z;
		
		
	    
	
		
		cout << "Please enter the first number : ";
		cin  >> x;
		cout << "Please enter the second number : ";
		cin >>  y;
		mylabel:
		cout << "Enter 1 for addition , 2 for multiplication: " << endl;
		cin >> z;
		
		
	
		
	

 if ( z == 1 )
		{
			
	    add Num;
		Num.getNum(x,y);
		
		cout << Num.addition();
		
	         }
		
	    if ( z == 2)
	        {
	    	Multiplication Numbers;
		Numbers.getNum(x,y);
		
	    	cout << Numbers.multiply();
	    	
		}
		else {
			cout << "Please enter one or two : ";
			
			goto mylabel;
			
		}

       

		return 0 ;
}

Thanks :)
Last edited on
closed account (48T7M4Gy)
Get rid of all the blank lines for a start.
Proper indentation - otherwise it looks like a bit of a dog's breakfast.
goto's are not good form either. try and get rid of them. :)
closed account (48bpfSEw)
Formating source code: http://format.krzaq.cc/


To write "efficient" you have to understand what it is:
http://www.dictionary.com/browse/efficient

Efficience has many aspects. From the viewpoint of the functionality : if your code does what it has to produce then it's efficient (enough)
closed account (48T7M4Gy)
efficient (enough)

In a word, 'sufficient'.
Topic archived. No new replies allowed.