LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-10-2004, 06:21 PM   #1
AFI_Flame
Member
 
Registered: Apr 2004
Location: Nolensville, TN
Distribution: OpenSuse 10.2
Posts: 253

Rep: Reputation: 30
C++ For Dummies


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.

Last edited by AFI_Flame; 10-10-2004 at 06:24 PM.
 
Old 10-10-2004, 09:15 PM   #2
cadj
Member
 
Registered: Aug 2003
Location: Melbourne Australia
Distribution: Debian Stretch
Posts: 374

Rep: Reputation: 32
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
 
Old 10-14-2004, 11:54 AM   #3
Thomasseafort
LQ Newbie
 
Registered: Oct 2004
Location: Fort Wayne IN
Distribution: Fedora, 2000pro, server
Posts: 26

Rep: Reputation: 15
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.
 
Old 10-14-2004, 11:56 AM   #4
Thomasseafort
LQ Newbie
 
Registered: Oct 2004
Location: Fort Wayne IN
Distribution: Fedora, 2000pro, server
Posts: 26

Rep: Reputation: 15
On second thought just comment out the last line and it will work
 
Old 10-14-2004, 08:28 PM   #5
AFI_Flame
Member
 
Registered: Apr 2004
Location: Nolensville, TN
Distribution: OpenSuse 10.2
Posts: 253

Original Poster
Rep: Reputation: 30
yea... I was wondering something else now... what does "return 0;" do? I was deleting that too.
 
Old 10-15-2004, 07:28 AM   #6
Thomasseafort
LQ Newbie
 
Registered: Oct 2004
Location: Fort Wayne IN
Distribution: Fedora, 2000pro, server
Posts: 26

Rep: Reputation: 15
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
 
Old 10-15-2004, 02:00 PM   #7
rustynailz
Member
 
Registered: Jun 2004
Distribution: MDK 9.2/10.0, VectorLinux 4.0
Posts: 50

Rep: Reputation: 15
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux For Dummies AnthonyB Linux - Software 9 11-26-2005 09:03 AM
SUSE Linux 9.3 for Dummies (For Dummies S.) samuelmp SUSE / openSUSE 11 08-01-2005 01:42 PM
Slackware for Dummies Ryuji Yamazaki Linux - Newbie 5 10-28-2004 02:52 PM
mandrake for dummies huffboy Linux - Newbie 2 04-27-2004 09:43 PM
eBooke for dummies deWin Linux - General 2 02-23-2004 03:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration