Results 1 to 7 of 7

Thread: I'm learning c++ and ran into a small snag

  1. #1
    Join Date
    Jan 2011
    Location
    New York
    Beans
    155
    Distro
    Ubuntu 12.04 Precise Pangolin

    I'm learning c++ and ran into a small snag

    I bought a "C++ for Dummies book" just started reading it and doing example code from the book in Code:Blocks 10.05, I'm running ubuntu 10.10 btw. anyway my exact code:
    Code:
    //
    //   Conversion - Program to convert temperature from
    //   Clesius degrees into Fahrenheit:
    //   Fahrenheit = Celsius  *  (212 - 32)/100 + 32
    //
    #include <cstdio>
    #include <cstdlib>
    #include <iostream>
    using namespace std;
    
    int main(int nNumberofArgs, char* pszArgs[])
    {
        // enter the temperature in celsius
        int celsius;
        cout << "Enter the temperature in Celsius:";
        cin >> celsius;
    
        // calculate conversion factor to convert celsius
        // into fahrenheit
        int factor;
        factor = 212 - 32;
    
        // use conversion factor to convert celsius
        // into fahrenheit values
        int fahrenheit;
        fahrenheit = factor * celsius/100 +32;
    
        // output the results (followed by a newline)
        cout << "Fahrenheit value is:";
        cout << fahrenheit << endl;
    
        // wait until user is ready before terminating program
        // to allow the user to see the program results
        system("PAUSE");
        return 0;
    }
    it compiles ok, and runs the program properly by asking me for temperature in celsius, and reads me back the conversion in fahrenheit, however at the very end i get as output:
    Code:
    sh: PAUSE: not found
    Anyone have any insight as to why this happens would be appreciated as the book states it should simply state "Press any key to continue..." which it does do but after the sh: PAUSE: not found message.

  2. #2
    Join Date
    Nov 2009
    Location
    East Anglia
    Beans
    415
    Distro
    Xubuntu

    Re: I'm learning c++ and ran into a small snag

    Quote Originally Posted by robgraves View Post
    I bought a "C++ for Dummies book" just started reading it and doing example code from the book in Code:Blocks 10.05, I'm running ubuntu 10.10 btw. anyway my exact code:
    Code:
       ...snip...
       system("PAUSE");
    it compiles ok, and runs the program properly by asking me for temperature in celsius, and reads me back the conversion in fahrenheit, however at the very end i get as output:
    Code:
    sh: PAUSE: not found
    Anyone have any insight as to why this happens would be appreciated as the book states it should simply state "Press any key to continue..." which it does do but after the sh: PAUSE: not found message.
    Take a look at:

    http://www.gidnetwork.com/b-61.html

    Basically
    "It's not portable. This works only on systems that have the PAUSE command at the system level, like DOS or Windows. But not Linux and most others..."
    H

  3. #3
    Join Date
    Mar 2010
    Location
    ρθΦ=000
    Beans
    Hidden!
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: I'm learning c++ and ran into a small snag

    Quote Originally Posted by robgraves View Post
    system("PAUSE");
    Is a terrible Windows specific command, for linux systems you'll want to use

    Code:
    cin.get();

  4. #4
    Join Date
    Jan 2011
    Location
    New York
    Beans
    155
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: I'm learning c++ and ran into a small snag

    excellent, that worked thank you

  5. #5
    Join Date
    Sep 2009
    Location
    Canada, Montreal QC
    Beans
    1,809
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: I'm learning c++ and ran into a small snag

    Terrible thing, I had the same problem with my python tutorials... Had to use raw_input.
    I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones.
    Freedom is measured in Stallmans.
    Projects: gEcrit

  6. #6
    Join Date
    Jan 2011
    Location
    New York
    Beans
    155
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: I'm learning c++ and ran into a small snag

    Quote Originally Posted by cgroza View Post
    Terrible thing, I had the same problem with my python tutorials... Had to use raw_input.
    i actually wanna learn python too, that's probably next on my list.

  7. #7
    Join Date
    Nov 2008
    Location
    Chicago, IL. U.S.A.
    Beans
    8
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: I'm learning c++ and ran into a small snag

    Thank you. It helped me out too.

    Quote Originally Posted by robgraves View Post
    excellent, that worked thank you

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •