Why do i get error C2181: illegal else without matching if?
Here's the code:
i get these errors:
error C2061: syntax error : identifier 'carrots2'
error C2181: illegal else without matching if
Code:
#include <iostream>
int main()
{
using namespace std;
int carrots;
cout << "How many carrots do you have?" << endl;
cin >> carrots; //User input
cin.get();
cout << "Here are two more. " << endl;
carrots = carrots + 2;
cout << "How many carrots do you have now?" << endl;
int carrots2;
cin >> carrots2;
cin.get();
if carrots2 == 8
cout << "That's correct" << endl;
else
cout << "That's incorrect" << endl;
cin.get();
return 0;
}
error C2061: syntax error : identifier 'carrots2'
error C2181: illegal else without matching if
