I can't seem to find the errors in this code. It's saying I have an else without if statements, as well as expecting { after a on line 19, and expected ; before {token.
#include<iostream>
usingnamespace std;
int main()
{
int a;
int b;
int sum;
cout << "Input a variable for a: ";
cin >> a;
cout << endl << endl << "Input a variable for b: ";
cin >> b;
sum = a + b;
cout << "the sum of a plus b is: " << sum;
if a(sum>=50){
cout << endl << endl << "The answer is greater than or equals to 50";
}else(sum<=50){
cout << endl << endl << "the answer is less than or equal to 50";
}
}
#include<iostream>
usingnamespace std;
int main()
{
int a;
int b;
int sum;
cout << "Input a variable for a: ";
cin >> a;
cout << endl << endl << "Input a variable for b: ";
cin >> b;
sum = a + b;
cout << "the sum of a plus b is: " << sum;
if (sum>=50){
cout << endl << endl << "The answer is greater than or equals to 50";
}else(sum<=50){
cout << endl << endl << "the answer is less than or equal to 50";
}
}
#include<iostream>
usingnamespace std;
int main()
{
int a;
int b;
int sum;
cout << "Input a variable for a: ";
cin >> a;
cout << endl << endl << "Input a variable for b: ";
cin >> b;
sum = a + b;
cout << "the sum of a plus b is: " << sum;
if (sum>=50){
cout << endl << endl << "The answer is greater than or equals to 50";
}else(sum<=50);{
cout << endl << endl << "the answer is less than or equal to 50";
}
}
is that normal? the guy in the turorial video didn't have that there, lol.
You can't have a condition after the else statement. Line 23 should just be: } else {
The else statement executes when the previous if statement(s) are false, so having a condition there is pointless.