Thread: .exe executing after final command.

  1. #16
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    I've know idea why you were using chars, try this. If I've got these code tags right.

    Code:
    #include <iostream.h>
    
    int main(void)
    {
      int min,max,i;
    
      cout << "Input your first number to count from: ";
      cin >> min;
    
      cout << "Input your last number to count to: ";
      cin >> max;
    
      for(i=min; i <= max; i++)
        cout << i << endl;
    
      system("pause");
      return 0;
    }
    Be a leader and not a follower.

  2. #17
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    yeah - the tutroial im using doesnt use chars - so they were confusing me !!

    tried that code

    Compiling...
    mark.cpp
    C:\Documents and Settings\Default\Desktop\test\mark.cpp(16) : error C2065: 'system' : undeclared identifier
    Error executing cl.exe.

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


    Its just not my day is it

  3. #18
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Take out the system code. That should work

  4. #19
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    yeah it compiles fine now...

    But i am back to step one where it executes

    Mark

  5. #20
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Frankly, I don't know what is wrong now.

  6. #21
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Use this

    Code:
    #include <iostream.h>
    
    int main(void)
    {
      int min,max,i;
    
      cout << "Input your first number to count from: ";
      cin >> min;
    
      cout << "Input your last number to count to: ";
      cin >> max;
    
      for(i=min; i <= max; i++)
        cout << i << endl;
    
      getchar();
      return 0;
    }

  7. #22
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    You are using MSVC++? Well then to save some trouble, when you want to test your program, press CTRL+F5 to have MSVC++ execute the program for you, plus if it's a console app (dos screen), it will automatically "pause" when it's finished

    just FYI

  8. #23
    Its not rocket science vasanth's Avatar
    Join Date
    Jan 2002
    Posts
    1,683
    if you are using VC++ try this

    Code:
    #include <iostream.h>
    
    int main(void)
    {
      int min,max,i;
    
      cout << "Input your first number to count from: ";
      cin >> min;
    
      cout << "Input your last number to count to: ";
      cin >> max;
    
      for(i=min; i <= max; i++)
        cout << i << endl;
    
    cout<<"\n Press a key to continue ";
    getch();
    return 0;
    }

  9. #24
    Registered User
    Join Date
    Jun 2002
    Posts
    9
    Compiling...
    Counting.cpp
    c:\documents and settings\default\desktop\c++\for loop\counting.cpp(17) : error C2065: 'getch' : undeclared identifier
    Error executing cl.exe.


  10. #25
    Registered User raimo's Avatar
    Join Date
    Jun 2002
    Posts
    107
    Code:
    #include <iostream>
    int main(void)
    {
      int min,max,i;
      cout << "Input your first number to count from: ";
      cin >> min;
      cout << "Input your last number to count to: ";
      cin >> max;
      for(i=min; i <= max; i++)
        cout << i << endl;
      cout<<"\nPress a key to continue ";
      while (cin.get() != '\n');
      cin.get();
      return 0;
    }
    This works for me and should work everywhere.
    Add using namespace std; like in one of the previous messages if this does not work. Generally one should use std:: before all the cout:s and cin:s.

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