ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
What's wrong with this code? I copied it exactly from the book.
Code:
//
// Program to convert temperature from Celsius degree
// units into Farenheit degree units:
// Farenheit = 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 for Celsius
// to 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 using g++ Conversion.cpp -o Conversion but when I go to run it this is what I get.
Code:
Enter the temperature in Celsius:45
Fahrenheit value is:113
sh: line 1: PAUSE: command not found
EDIT: Woops I just found another post with this exact problem lol. If I knew how to close this thread I would.
system("PAUSE"); this is ment for a windows (DOS) system, your program is trying to run the "pause" program which shows a "press any key to continue" im not sure what the linux equiv is
I agree with cadj there is no Pause command that is why command not found error.
You can try using the break In C++
You can use an if command to see a cin and then a timer. Or you could use a case and switch command.
Return is the enter ket on keyboard, (0) means nothing so when you return nothing or null the program stops I did'nt mean to comment that out the line above it
main() is a function just like any other. The return value of it is available to the caller (in this case the CLI). It's typical practice to return 0 when all is well, and non-zero otherwise. For example, suppose a user enters invalid input for one of the cin>>s. You could read the input as a string, check to see if it's valid, and if not, print an error message and return 1.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.