Results 1 to 3 of 3

Thread: c++ error message - pls check it out!

  1. #1
    Senior Member
    Join Date
    Dec 2001
    Posts
    338

    c++ error message - pls check it out!

    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().

  2. #2

    Re:c++ error message - pls check it out!

    [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]

    Code:
    #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;
    }
    hth

  3. #3

    Re:c++ error message - pls check it out!

    Code:
    #include <iostream.h>
    
    using namespace std;
    
    int main()
    {
      int num;
    
      cout << "enter an integer\n";
      cin >> num;
     
      if (num % 2 == 0) {
        cout << "that integer is even";
      } else { 
        cout << "that integer is odd";
      }
    
      return 0;
    }

Similar Threads

  1. Runtime Error message
    By PuppyDogMom in forum Windows - General Topics
    Replies: 0
    Last Post: 10-15-2006, 04:46 PM
  2. Apache error 403 forbidden message
    By isaac in forum Linux - Software, Applications & Programming
    Replies: 4
    Last Post: 02-02-2005, 03:32 AM
  3. error message on administration page
    By regix in forum Windows - General Topics
    Replies: 0
    Last Post: 01-01-2005, 09:02 PM
  4. Squid | Webmin | Error message
    By crazy ivan in forum Linux - Software, Applications & Programming
    Replies: 7
    Last Post: 11-07-2003, 08:46 PM
  5. error message
    By and1088 in forum Linux - Hardware, Networking & Security
    Replies: 8
    Last Post: 03-04-2002, 11:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •