what's wrong

This is a discussion on what's wrong within the C++ Programming forums, part of the General Programming Boards category; this is my code Code: #include <iostream.h> #include <stdlib.h> int main() { int regio; cout <<" (c) copyright www.gratischeck.web1000.com \n"; ...

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

    what's wrong

    this is my code

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
     int regio;
    
     cout <<" (c) copyright www.gratischeck.web1000.com \n";
     cout <<"beantwoord de volgende vragen\n";
     cout <<"belt uw in de regio of buiten de regio het meeste\n";
     cout <<"regio : 1  buiten regio : 2 \n"  ;
     cin>>regio;
     goto callreg;
     system("pause");
    
     int callreg();
    {
    if (regio = 1)
    {
    cout <<"uw belt in de regio het meest\n";
    goto pause;
    }
    if (regio = 2) ;
    {
    cout <<"uw belt het meeste niet in uw regio\n";
    goto pause;
    }
    }
    
    int pause()
    {
    system("pause") ;
    }
    i get these error messages

    c:\docume~1\php---~1\mydocu~1\tel\untitl~1.cpp: In function `int main()':
    c:\docume~1\php---~1\mydocu~1\tel\untitl~1.cpp:31: parse error before `{'
    c:\docume~1\php---~1\mydocu~1\tel\untitl~1.cpp:21: label `pause' used but not defined
    c:\docume~1\php---~1\mydocu~1\tel\untitl~1.cpp:13: label `callreg' used but not defined

    i can't find the problem
    Attached Files Attached Files
    if x == y , y == x

  2. #2
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    Posts
    128
    Uh, you can't call functions with goto. Instead of "goto callreg" you would do "callreg()"

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

    Thumbs down re:

    i try'd to change

    goto pause;

    and changed in to

    goto pause();

    it ditn't work

    and of course

    changing it to

    pause()

    isn't right to
    if x == y , y == x

  4. #4
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    Posts
    128
    Yes it is.

    EDIT: Try putting int pause (); and int callreg() ; at the top of your program. You might also want to close the bracket on main() and remove the semicolon after callreg() and the if statement in callreg()

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    There are actually lots of little problems with your code.

    1. You can't define a function inside main(). Move the callreg function outside and below main.
    2. You need a function prototype above main() for your two functions - callreg and pause. For example:

      int callreg();
    3. Your if statements are not correct. You should use:

      if (regio == 1)

      Otherwise your are assigning 1 to regio instead of comparing 1 to regio.
    4. You are using old and deprecated header files. Change your includes to:

      #include <iostream>
      #include <cstdlib>
      using namepsace std;

    5. And finally, change your function calls to:

      callreg();

      and

      pause();

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    i have changed my code
    Code:
    #include <iostream>
    #include <stdlib.h>
    
    int pause()
    {
    system("pause") ;
    }
    
    int hello();
    {
    if (regio == 1)
    {
    cout <<"uw belt in de regio het meest\n";
    goto pause;
    }
    if (regio == 2) ;
    {
    cout <<"uw belt het meeste niet in uw regio\n";
    goto pause;
    }
    }
    
    int main()
    {
     int regio;
     cout <<" (c) copyright www.gratischeck.web1000.com \n";
     cout <<"beantwoord de volgende vragen\n";
     cout <<"belt uw in de regio of buiten de regio het meeste\n";
     cout <<"regio : 1  buiten regio : 2 \n"  ;
     cin>>regio ;
     goto hello();
     system("pause");
     }
    iam trying to get the last 3 bugs out


    c:\docume~1\php---~1\my documents\tel\untitled2.cpp:10: parse error before `{'
    c:\docume~1\php---~1\my documents\tel\untitled2.cpp: In function `int main()':
    c:\docume~1\php---~1\my documents\tel\untitled2.cpp:31: parse error before `('
    if x == y , y == x

  7. #7
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    Posts
    128
    Are you not listening at all?

    Remove every goto you have in there.

    Code:
    int hello();
    Right there, you need to remove the semicolon.

    Code:
    if (regio == 2) ;
    Right there, you need to remove the semicolon.

    Code:
    goto pause;
    change this to pause(); No goto. Same with

    Code:
    goto hello();
    That needs to be just hello() ;

  8. #8
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    I'm wondering, are you trying to implement goto, or are you trying to implement a function. They are of course two very different things.

    If you are trying to implement a function (which I believe is generally accepted as being infinitely better than using goto), then follow w00tsoft's advice.

    In addition, when calling a function you must understand that the variables that you declare and use in one function (like main()) are not available to use in another function (like hello()). In your code, you declare and use regio in main(), then use it in hello(). The problem is that hello() doesn't know about this variable.

    To fix it you will have to pass the variable into your function.

    And finally, good job on changing to <iostream> instead of <iostream.h>, but you didn't follow my advice completely, and so your code will still not work. You left out the using namespace std; part under the includes.

  9. #9
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    i dit it but
    in this part is stil 1 error
    Code:
    int hello();
    {
    if (regio == 1)
    {
    
    it says before the first {
    what iam meanning to

    is

    - yes
    yes or no -yes
    - no - next - yes or no
    -no
    Last edited by gamer; 10-16-2003 at 01:24 PM.
    if x == y , y == x

  10. #10
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    Originally posted by w00tsoft
    Are you not listening at all?
    Code:
    int hello();
    Right there, you need to remove the semicolon.
    Uhh, you didn't remove the semicolon (you know, the ';' character that you put after ()).

    You should only put the semicolon if it is a prototype (meaning you aren't defining the function).

    If you are defining the function (meaning you put { ...code... }), then you don't want the semicolon.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 07-15-2004, 04: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, 10:50 PM
  3. Confused: What is wrong with void??
    By Machewy in forum C++ Programming
    Replies: 19
    Last Post: 04-15-2003, 01:40 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Whats wrong?
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 07-14-2002, 02:04 PM

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