Thread: c++ beginner help

  1. #1
    I eat babies
    Join Date
    Jan 2008
    Location
    la-la-land
    Posts
    31

    c++ beginner help

    im learning c++ using a book i got from the library and i have a question about it
    Code:
    // using const.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
    	const int inches_per_foot = 12;
    	const int feet_per_yard = 3;
    	int yards = 0;
    	int feet = 0;
    	int inches = 0;
    
    	cout << "Enter a length as yards, feet, and inches: ";
    	cin >> yards >> feet >> inches;
    
    	cout << "\nLength in inches is " << inches + inches_per_foot * (feet + feet_per_yard * yards) << "\n\a";
    
    return 0;
    }
    im using microsoft visual c++ 2008 and whenever i debug the program it closes before i see the output, is there a thing that i should change so that it doesnt close without user input

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    cin.get, read the faq, Ctrl+F5 (no debugging) or place a breakpoint at the end of the program (F9) and run with debugging (F5).
    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.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Click here for the answer in the FAQ.

    Note that this has nothing to do with C+ itself. It is a feature of the Windows operating system. Windows closes your Window when your program ends.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Or click here for the answer in the Wiki: http://cpwiki.sourceforge.net/Pause_console
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    You guys need to put the FAQ for stopping the program from quitting on the homepage or something - it just gets asked so much.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    It is on the main page --
    How to keep a Windows console from closing.
    You have to keep checking it, it changes by the minute.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    I eat babies
    Join Date
    Jan 2008
    Location
    la-la-land
    Posts
    31
    sorry if this gets posted a lot, im just a beginner who came to a good looking site for help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 11:48 AM
  2. What are some good beginner programs I shouold make?
    By oobootsy1 in forum C# Programming
    Replies: 6
    Last Post: 08-09-2005, 02:02 PM
  3. Books, Beginner, MustHave
    By Zeusbwr in forum C++ Programming
    Replies: 9
    Last Post: 10-25-2004, 05:14 PM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM