[quote author=capybara link=board=9;threadid=4887;start=0#48681 date=1031452441]
heres what i wrote, a simple prog to tell if an integer is odd or even
====================================
#include <iostream>;
using std::cin;
using std::cout;
int main()
{
int num1,num2;
cout<<"enter an integer\n";
cin>>num1;
num % 2 ==num2;
if (num2 = 0)
cout<<"that integer is even";
if (num2 != 0)
cout<<"that integer is odd";
return 0;
}
============================================
but when it try to run gcc or g++, heres the error message:
line 14 [the second cout] no match for
'_IO_ostream_withassign & << const char[21]'
line 16 [the last cout] no match for
'_IO_ostream_withassign & << const char[20]'
============================================
im clueless , any ideas out there???
++++++++++++++++++++++++++++++++++++++++++++
also: i originally had the "using" statements before
int main() but that wouldnt work, i got the error
'cout' undeclared and 'cin' undeclared , but i fixed that by moving those "using" statement to after int main().
[/quote]
hthCode:#include <iostream> //no semicolon using namespace std; int main() { int num1,num2; cout << "enter an integer\n"; cin >> num1; //notice num2 should be on the left of the assignment //operator num2 = num1 % 2; //don't use == for assignment if (num2 == 0) //use == for comparison cout << "that integer is even"; if (num2 != 0) cout << "that integer is odd"; return 0; }


Reply With Quote
Bookmarks