Super Quick Help

This is a discussion on Super Quick Help within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream>using namespace std; int main() { int a; int b; int c; cout << "Enter a number:" << ...

  1. #1
    Registered User Black_Epiphany's Avatar
    Join Date
    Sep 2011
    Posts
    15

    Super Quick Help

    Code:
    #include <iostream>using namespace std;
    
    
    int main()
    {
    	int a;
    	int b; 
    	int c;
    
    
    	cout << "Enter a number:" << endl;
    	cin >> a;
    	cout << "Enter a number:" << endl;
    	cin >> b;
    
    
    	c = a + b;
    
    
    	cout << "The sum of those numbers is:" << endl;
    	cout << c;
    	cin.get();
    }
    I wrote this, tried to run it and it just closes the console as soon as the program is finished. What did I do wrong?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,993
    Run your program in a separate command prompt window.

    If you really want to do it this way, then insert a cin.ignore() before the cin.get() to ignore the newline character left in the input buffer from cin >> b;
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User Black_Epiphany's Avatar
    Join Date
    Sep 2011
    Posts
    15
    Thanks!

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,829
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Nov 2011
    Posts
    2
    I was curious, your compiler does not complain that you omit
    Code:
    return 0;
    in
    Code:
    main();

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,829
    No, it is not required by the standard.
    If omitted, the compiler will add an implicit return 0.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Super Tic Tac Toe
    By mcdant01 in forum C++ Programming
    Replies: 10
    Last Post: 09-15-2009, 05:15 PM
  2. Super in need of Help
    By Psyche in forum C Programming
    Replies: 2
    Last Post: 07-10-2008, 10:42 AM
  3. iMalc Super Quick Sort
    By bean66 in forum C Programming
    Replies: 9
    Last Post: 08-23-2007, 09:09 PM
  4. Which super hero(ine) are you?
    By biosninja in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-15-2002, 06:36 AM
  5. Super quick ? here
    By CAP in forum C Programming
    Replies: 9
    Last Post: 08-03-2002, 12:35 PM

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