Help with calling function

This is a discussion on Help with calling function within the C++ Programming forums, part of the General Programming Boards category; i cant get my program to call thew function please help Code: #include <stdio.h> #include <stdlib.h> #include <iostream.h> int main() ...

  1. #1
    Registered User mill1000's Avatar
    Join Date
    Nov 2001
    Posts
    45

    Unhappy Help with calling function

    i cant get my program to call thew function please help
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    int main()
    {
      int sel;
      cout<<"Menu Program 2.0\n";
      cout<<"1. Bet You Can't\n";
      cout<<"2. Two Number Calculater\n";
      cout<<"3. Optical Illusion\n";
      cout<<"4. Quit\n";
      cout<<"Select A Operation:";
      cin>>sel;
      switch(sel)
      {
      case 1:
      int BYC();
      case 2:
      int TNC();
      case 3:
      int OI();
      }
    }
    int BYC()
    {
    cout<<"hi";
    system("pause");
    }

  2. #2
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    initialize sel (ex int sel =0;)
    switch statement should have break statement..
    int byc() has no return value..

    If u correct all that i think it should work fine..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    11
    it should be like this...
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    int main()
    {
      int sel;
      cout<<"Menu Program 2.0\n";
      cout<<"1. Bet You Can't\n";
      cout<<"2. Two Number Calculater\n";
      cout<<"3. Optical Illusion\n";
      cout<<"4. Quit\n";
      cout<<"Select A Operation:";
      cin>>sel;
      switch(sel)
      {
      case 1:
      BYC();
      break;
      case 2:
      TNC();
      break;
      case 3:
      OI();
      break;
      }
    
     return 0;
    }
    void BYC (void)
    {
     cout<<"hi";
     system("pause");
    }
    you're problem is that you are not using value returning functions but attempting (wrongly) to call them, plus int main () is a value returning function and has to have return 0; at the end, and with system ("pause"); you need the windows headerfile to use. I suggest you go through each tutorial on this website and maybe get yourself a book. You still need to write the other functions!
    “The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs.” - Joseph Weizenbaum

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by dsig111
    it should be like this...
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream.h>
    int main()
    {
      int sel;
      cout<<"Menu Program 2.0\n";
      cout<<"1. Bet You Can't\n";
      cout<<"2. Two Number Calculater\n";
      cout<<"3. Optical Illusion\n";
      cout<<"4. Quit\n";
      cout<<"Select A Operation:";
      cin>>sel;
      switch(sel)
      {
      case 1:
      BYC();
      break;
      case 2:
      TNC();
      break;
      case 3:
      OI();
      break;
      }
    
     return 0;
    }
    void BYC (void)
    {
     cout<<"hi";
     system("pause");
    }
    you're problem is that you are not using value returning functions but attempting (wrongly) to call them, plus int main () is a value returning function and has to have return 0; at the end, and with system ("pause"); you need the windows headerfile to use. I suggest you go through each tutorial on this website and maybe get yourself a book. You still need to write the other functions!
    fxn also needs to be prototyped before main, or written in it's entirety above main.

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    11
    yeah there are alot of errors I can't even catch because the code is a little sloppy and I suggest starting over!
    “The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs.” - Joseph Weizenbaum

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Originally posted by dsig111
    yeah there are alot of errors I can't even catch because the code is a little sloppy and I suggest starting over!
    not that sloppy. after your fixes, the prototype/above main, and standard compliance; it should be okay. i haven't compiled it though.

  7. #7
    Registered User mill1000's Avatar
    Join Date
    Nov 2001
    Posts
    45
    thanks guy i fiqured out some error on my own and i dont need the include <windows.h>

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Replies: 28
    Last Post: 07-17-2006, 12:35 AM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 09:56 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 07:39 AM
  5. Question on function syntax and calling function
    By cbrman in forum C Programming
    Replies: 10
    Last Post: 10-05-2003, 06:32 PM

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