Simple Arithmetic operations help!

I need help with this code, Ive started writing but for some reason my code isn't working, If anyone can help me i would be very much grateful. Thanks

The first option the user is required to enter three I want the complier to add three numbers and displaying the sum.

The second option is adding first two numbers entered and dividing the third number entered and displaying result

The third option is subtracting first number entered and from the second number entered then result of subtacting the second number from the third number entered. The program should say which of the two results is lowest.

The forth option requires the user to enter 3 numbers and listing them highest, lowest and in the middle.

The fifth number the user is required to enter 3 numbers the first number multiplied by the second is greater than 0 and a message should be output,otherwise if the third number is greater than the first second a message should input. If no option is chosen the program should output a message saying so
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
  #include <iostream>
#include <conio.h> 
#include <stdio.h>

using namespace std;

int main()
{
   int choice; 
   start:
   cout <<"Choose Option";               
   cin>>choice; 

    //option 1
   if (choice ==1)
  {

  int number1, number2, number3; 
  system ("cls");
  cout << "OPTION 1/n/n/n";
    int number1; // Declare number1 as an integer variable
	int number2;
	int number3
	int result
	int result1;

	cout <<"Enter first number: ";
	cin >> number1;

	cout <<"Enter second number: ";
	cin >> number2;

	cout <<"Enter third number ";
	cin >> number3

		result = number1 + number2 + number3 

	cout << "Result" << number1 << "add"  << number2  << "add" << number3
	     << "is" << result << endl;
if (choice == 2)   
                               

  {
   int number1, number2, number3 ,result;
   cout <<"Enter first number: ";
	cin >> number1;

	cout <<"Enter second number: ";
	cin >> number2;

	cout <<"Enter third number ";
	cin >> number3

		result = number1 - number2 / number3 

	cout << "Result" << number1 << "subtract"  << number2  << "divide" << number3
	     << "is" << sum << endl;
    system ("cls");

      cout << "OPTION 2";

  {

if (choice == 3)   
                               

  {
   int number1, number2, number3, result, result1;
    cout <<"Enter first number: ";
	cin >> number1;

	cout <<"Enter second number: ";
	cin >> number2;

	cout <<"Enter third number ";
	cin >> number3

		result = number1 - number2 
		result1 = result - number3 

		if(result > result1)

	cout << "Result" << number1 << "and"  << number2  << "and" << number3
	     << "is" << result << endl;
    system ("cls");


      cout << "OPTION 3";

  {
int number1, number2, number3, result;
if (choice == 4)   
                               

  {
   int number1, number2, number3, result;
    cout <<"Enter first number: ";
	cin >> number1;

	cout <<"Enter second number: ";
	cin >> number2;

	cout <<"Enter third number ";
	cin >> number3

	if(number1 > number2)
{
	cout << "number1 is Higher" << endl;

	if(number1 < number2)

		cout << "number 2 is Higher"

	if(number1 > number3)

		cout << "number1 is Higher"

	if(number3 > number1)
		cout <<"number3 is higher"

}int highest_number=10;

int input_number;

cin >> input_number;
	
if(input_number > highest_number) 
{		
	cout << " highest number." << endl;
	highest_number = input_number;
} 

if(input_number <= highest_number) 
{		
	cout << "Number is not the highest." << endl;



		if(number1 < number2 > number3)	

	cout << "Result" << number1 << "and"  << number2  << "and" << number3
	     << "is" << result << endl;
    system ("cls");

      cout << "OPTION 4";

  {

 if (choice == 5)                                    

    {
    int number1, number2, number3, result;
    system ("cls");

    cout << "OPTION 5\n";
    	return 0;
}

    //SELECTION ERROR
    if ((choice > 5) || (choice < 1))                                
    {
      system("cls");
      cout << "\n\nERROR. PLEASE SELECT 1 - 5 ONLY.";
      cout << "\n\n\n\nPress a key to return to selection menu...";
      _getch();
      goto start;
    }
    }
Last edited on
On line 18 you've declared 3 ints:

int number1, number2, number3;

Yet 3 lines later you've declared them again:
1
2
3
    int number1; // Declare number1 as an integer variable
	int number2;
	int number3 // missing ;  


Also you've not ended a lot of your statements with a semicolon. BUT this is fine:

1
2
cout << "Result" << number1 << "add"  << number2  << "add" << number3 // don't put ; here!
<< "is" << result << endl; // remember this is one chained output in a single statement  


Also pay attention to your block braces { }. Remember } pairs with the last {. You have some messed up there. If you use something like Code::Blocks or Visual Studio, clicking the brace should show the corresponding one.

I haven't checked the rest but try fixing those. I don't know why you need conio.h. I don't know what it is but I don't see any code that might use it. Also, remember when you use headers, use the C++ versions. Change your 3rd include to #include <cstdio> . Unless it's your own header, the .h ones are old C ones. So if you're told to #include <math.h> , you remove .h and stick a 'c' at the beginning of the name: #include <cmath> .

Last edited on
Topic archived. No new replies allowed.