Thread: .exe executing after final command.

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    9

    .exe executing after final command.

    Hello - first post here - hopefully someone can help

    Im fairly new to C++, I've got MS Visual and I was experimenting the other day and came across a problem.

    I found a simple script and entered it into MS Visual.

    PHP Code:

    #include <iostream>
    using namespace std;

    void main()
    {

    int min=0max=0i=0;

    cout << "Input your first number to count from: ";

    cin >> min;

    cout << "Input your last number to count to: ";

    cin >> max;

    for(
    i=min<= maxi++)
    {
    cout << << endl;
    }


    So I entered that into MS VIsual, Complied it and found the finished product.

    I opened the .exe and the black screen appeared.

    It asked me for the first number - I entered it

    It asked me for the second number - I entered it

    Then as soon as I have pressed return it showed me the numbers inbetween for about 0.1 of a second and shut down.

    I know that after I press return it should say "press any key to continue" On mine - it doesnt.

    So basically does anyone know why is executes after that command, and how I can fix it...

    By the way I have tried with more than one script and it always shuts down at the end.

    Thanks in advance

    Mark

  2. #2
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    You need to hold the screen to show the results.

    getchar();

  3. #3
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644

    Re: .exe executing after final command.

    Originally posted by Mark UKBB

    PHP Code:
    for(i=min<= maxi++)
    {
    cout << << endl;
    }


    Inbetween the } and the } should be a return 0;

  4. #4
    Unregistered
    Guest

    Re: Re: .exe executing after final command.

    Originally posted by Quantrizi

    Inbetween the } and the } should be a return 0;
    Not since he's using void main()

  5. #5
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Actually, he should. It doesn't matter.

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    Hi - thanks for the quick reply.

    I entered the return 0;

    the script still executes.....

    Subdene - what does getchar(); do and where shall I enter it?

    Thanks

    Mark

  7. #7
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    getch(); reads a keypress

  8. #8
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    where do I put it??

    Sorry if I seem stupid... I never have this problem with php.... but then again they are completly different lol

    Mark

  9. #9
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    That one I can't tell you because I never use it (never works for me), but you put that were you want the user to press a key. But if your doing console programming, just use cin >>.
    [EDIT]For input, try using char. Do it like this instead of int:
    Code:
    char i[10];
    and do it that way
    Last edited by Quantrizi; 06-15-2002 at 05:50 PM.

  10. #10
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    Still executes.....

    This is getting silly now......

    Im sure I am doing everything correctly.....


  11. #11
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    PHP Code:
    #include <conio.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    using namespace std;

    void main(int argcchar *argv[])
    {

    char min[20], max[20], i[20];

    cout << "Input your first number to count from: ";

    cin >> min;

    cout << "Input your last number to count to: ";

    cin >> max;

    for(
    i=min<= maxi++)
    {
    cout << << endl;
    }
    system("pause");
    return 
    0;

    That should work.

  12. #12
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    Entered that text and compiled it..... whilst compiling got these errors..



    c:\documents and settings\default\desktop\test\mark.cpp(20) : error C2106: '=' : left operand must be l-value
    c:\documents and settings\default\desktop\test\mark.cpp(20) : error C2105: '++' needs l-value
    c:\documents and settings\default\desktop\test\mark.cpp(25) : error C2562: 'main' : 'void' function returning a value
    c:\documents and settings\default\desktop\test\mark.cpp(7) : see declaration of 'main'
    Error executing cl.exe.

    mark.exe - 3 error(s), 0 warning(s)


    Now im confused!

  13. #13
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    me to now.....

  14. #14
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    If you are using the ansi standard there should be no ".h" after the header file. That should sort it out.
    Be a leader and not a follower.

  15. #15
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    down to one error

    Compiling...
    mark.cpp
    c:\documents and settings\default\desktop\test\mark.cpp(1) : fatal error C1083: Cannot open include file: 'conio': No such file or directory
    Error executing cl.exe.

    mark.exe - 1 error(s), 0 warning(s)


    Sorry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Executing an external shell command
    By g4j31a5 in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2007, 07:47 PM
  3. system command not executing with format specifier
    By ridhamshah in forum C Programming
    Replies: 6
    Last Post: 11-08-2006, 05:58 AM
  4. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  5. Replies: 1
    Last Post: 03-11-2003, 05:36 PM