whats wrong with the if statments

This is a discussion on whats wrong with the if statments within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream.h> #include <stdlib.h> #include <string> int main() { int watdoyousee ; cout <<"filler V0.1 unregistert version\n"; cout <<"\n\n\n\n\n"; ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    56

    Thumbs down whats wrong with the if statments

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <string>
    
    int main()
    {
          int watdoyousee    ;
          cout <<"filler V0.1 unregistert version\n";
          cout <<"\n\n\n\n\n";
          cout <<"1.unpack\n";
          cout <<"2.pack\n";
          cin>>watdoyousee      ;
    
          if  (watdoyousee == 1);
          {
          cout <<"dombo\n\n";
          }
          if (watdoyousee == 2);
          {
          cout <<"goedso\n\n";
          }
          return main();
    }
    the problem if the outputs come
    it wil say when you do 1

    dombo

    goedso

    also with 2

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    91
    You need to use switch satements.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    i wil look that up in my book
    thanks for the help

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    Code:
    int main()
    {
          int watdoyousee    ;
          cout <<"filler V0.1 unregistert version\n";
          cout <<"\n\n\n\n\n";
          cout <<"1.unpack\n";
          cout <<"2.pack\n";
          cin>>watdoyousee      ;
    
          if  (watdoyousee == 1); <-- take off the semicolon 
          {
              cout <<"dombo\n\n";
          }
          if (watdoyousee == 2); <-- take off the semicolon 
          {
              cout <<"goedso\n\n";
          }
          return main(); <-- change it to return 0  
    }
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  5. #5
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    that works just taking of the ; selicoms

  6. #6
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164
    Your returning the function main() to an integer???

    Listen to what alphaoide said, main will return 0.

    Also, you only need 1 include. <iostream> (drop the .h, they are depricieted)


    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
          int watdoyousee;
          cout <<"filler V0.1 unregistert version\n";
          cout <<"\n\n\n\n\n";
          cout <<"1.unpack\n";
          cout <<"2.pack\n";
          cin>>watdoyousee;
    
          if  (watdoyousee == 1)
          {
              cout <<"dombo\n\n";
          }
          else if (watdoyousee == 2)
          {
              cout <<"goedso\n\n";
          }
          else
          {
               cout << "Unknown option '" << watdoyousee << "'\n";
          }
          return 0;
    }
    Last edited by eth0; 01-14-2004 at 02:06 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  2. Debugging-Looking in the wrong places
    By JaWiB in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 11-03-2003, 09:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 12:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 11:01 AM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 01:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21