What am I doing rong with my program !!!

This is a discussion on What am I doing rong with my program !!! within the C++ Programming forums, part of the General Programming Boards category; I wrte a simple program and whin I run it I doesn't stay up long enugh to see the results. ...

  1. #1
    Chance
    Guest

    Exclamation What am I doing rong with my program !!!

    I wrte a simple program and whin I run it I doesn't stay up long enugh to see the results. Here is my small program. "What's wrong."

    //
    // Conversion - convert temperature from Celsius
    // degree units into Fahrenheit degree
    // units:
    // Fahrenheit = Celsius * (212 - 32)/100 + 32
    //
    #include <stdio.h>
    #include <iostream.h>
    int main(int nNumberofArgs, char* pszArgs[])
    {
    // enter the temperature in Celsius
    int nCelsius;
    cout << "Enter the temperature in Celsius:";
    cin >> nCelsius;

    // calculate conversion factor for Celsius
    // to Fahrenheit
    int nFactor;
    nFactor = 212 - 32;

    // use conversion factor to convert Celsius
    // into Fahrenheit values
    int nFahrenheit;
    nFahrenheit = nFactor * nCelsius/100 + 32;

    // output the results
    cout << "Fahrenheit value is:";
    cout << nFahrenheit;

    return 0;
    }

  2. #2
    Registered User matheo917's Avatar
    Join Date
    Sep 2001
    Posts
    279
    i just compiled your program an it works fine.....

    the reason why the program doesn't "stay" long enough b/c you are writing a console program under windows... if you would to run this program in MS-Dos it would be different...

    if you want to stay in windows here's how to fix it....

    - on the top ... where your include statements are put...

    #include <stdlib.h>

    and on the bottom .... right before the "return 0" statment put...

    system("pause");

    what this will do is.... as you to press any key to continue (hold the programs execution) the reason why you put this before your last return statment is b/c the "return" stament will end the "main" function and terminate the program...

    hope this helps....

    Regards,
    matheo917

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    system("pause")

    hmm?? I thought that the function system(...) required <process.h>?????
    zMan

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > required <process.h>?????

    No....

    An alternative would be to include getch() at the end (also in stdlib.)

  5. #5
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    govtcheez is right, getch() is better - try to avoid system calls if you can. The code you want is

    int wait1 = getch();
    return 0;


    this will wait for a keypress before the program exits
    you nee to include conio.h for this
    Monday - what a way to spend a seventh of your life

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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