Reputation: 11
I'm doing homework in C++ using code blocks. The task was to write a program that will determine if a number is odd or even. Code is below.
#include <iostream>
using namespace std;
int number;
int main()
{
cout<<"Please enter number"<<endl;
cin>>number;
if(number%2==0)
{
cout<<"The number:"<<number<<" is even" <<endl;
}
else()
{
cout<<"The number:"<<number<<" is odd" <<endl;
}
return 0;
}
Upvotes: 0
Views: 74
Reputation: 197
You have else()
in your code (above the return statement). else
does not need parentheses after it. Also be aware that you probably don't need to have number as a global variable in this situation. If it MUST be global, do it, but otherwise try to keep your variables scoped in a class or function.
Upvotes: 5