im not getting what im doing wrong, coding for c++ Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 #include using namespace std; int main() { int a = 3, b = 15, c = 7; cout << a << b << c; cin >> 3 >> 15 >> 7; //a = 3, b = 15, c = 7 if (a < b && a < c) cout << " a " << 3; } else if (b > a && b < c) cout << " b " << 7; } else (c < a && c < b) cout << " c " << 15; } return 0; }
im not getting what im doing wrong, coding for c++
Write a
Ex: If the input is:
7 15 3
the output is:
3
#include <iostream>
using namespace std;
int main() {
int a = 3, b = 15, c = 7;
cout << a << b << c;
cin >> 3 >> 15 >> 7; //a = 3, b = 15, c = 7
if (a < b && a < c)
cout << " a " << 3;
}
else if (b > a && b < c)
cout << " b " << 7;
}
else (c < a && c < b)
cout << " c " << 15;
}
return 0;
}
There are several issues with your code. I'll correct them step by step:
- You should remove the initial assignments to
a
,b
, andc
because you want to take user inputs for these values. - You should use appropriate variables in your
if
conditions. - You need to use
&&
for the conditions properly. - You should remove unnecessary numbers from the
cin
statement.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images
this is the error im getting now
main.cpp:16:4: error: expected unqualified-id before ‘else’
16 | else if (b <= a && b <= c)
| ^~~~
main.cpp:19:4: error: expected declaration before ‘}’ token
19 | }
| ^
main.cpp:21:4: error: expected unqualified-id before ‘else’
21 | else {
| ^~~~
main.cpp:27:4: error: expected unqualified-id before ‘return’
27 | return 0;
| ^~~~~~
main.cpp:28:1: error: expected declaration before ‘}’ token
28 | }
| ^