Whats wrong with my program?

This is a discussion on Whats wrong with my program? within the C++ Programming forums, part of the General Programming Boards category; I'm not really making a real program. I'm just playing around with the new functions I recently learned. #include <iostream.h> ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    106

    Whats wrong with my program?

    I'm not really making a real program. I'm just playing around with the new functions I recently learned.

    #include <iostream.h>
    #include <conio.h>
    #include <conio.c>

    typedef unsigned short int USHORT;
    void after();

    void after()
    {
    USHORT Width = 5;
    USHORT Length;
    Length = 10;
    USHORT Area = Width * Length;
    cout << "\nWidth:" << Width << "\n";
    cout << "Length: " << Length << endl;
    cout << "Area: " << Area << endl;
    }

    int main()
    {
    int coul;
    cout << "Press 1 and/or 2 to continue.......\n";
    cin >> coul;
    if (coul==1 || coul==2) {
    void after(); }
    getch();
    return 0;
    }

  2. #2
    Unregistered
    Guest
    in main() you have the line:

    void after(); }

    Drop the word void in this line and recompile

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    106

    ok

    ok, I'll try that. By the way, it compiles successfullly, its just that when I press 1 or 2 it doesn't call after();

  4. #4
    Unregistered
    Guest
    if (coul==1 || coul==2)

    needs to be changed b/c your not working with numbers
    your working with a basic string

    if(coul == "1" || coul == "2")

    This should fix it

  5. #5
    Registered User
    Join Date
    Jan 2002
    Posts
    106

    yo

    btw, I'm using Dev-C++. How is it a basic string when it is declared as an integer?

  6. #6
    Unregistered
    Guest
    The linker should link conio.c to your program if you include conio.h, so I would try dumping that too.

    I agree with you, coul is of type int, and you should not try to equate that with a literal string.

    I would try bringing the function body for after() into main() and comment out the function definition and function call. I would do this first without an if statement checking coul. If that compiles and runs then I would place the code for the function body of after() in an if statement such as you have. If that compiles and runs appropriately, then I would try it again with everything uncommented. If it still doesn't work, then I would scream foul.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Maze Program - What am I doing wrong?
    By Gipionocheiyort in forum C++ Programming
    Replies: 20
    Last Post: 08-02-2007, 02:31 PM
  2. Replies: 5
    Last Post: 01-13-2007, 02:14 AM
  3. What is wrong with my code? My first program......
    By coreyt1111 in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2006, 02:03 PM
  4. Whats wrong with this program - Output of a series
    By duffmckagan in forum C Programming
    Replies: 2
    Last Post: 07-26-2006, 10:57 AM
  5. do you see anything wrong with this program?
    By seal in forum C Programming
    Replies: 3
    Last Post: 09-22-2005, 08:43 AM

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