Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

# C++ Help Needed

12 replies to this topic

### #1 Kanye

Kanye

• Members
• 97 posts
• OFFLINE
•
• Gender:Male
• Local time:08:26 AM

Posted 20 September 2008 - 11:40 AM

Hey this is my code for a simple conversion program to convert temperature in Celsius to Fahrenheit. I got the code from the For Dummies book and for some reason whenever I attempt to compile it, it's saying that there are several errors. I'm the type who needs to get something to work first and apply what was used to similar other programs before evolving to different things. Can someone please tell me what's wrong this code of mine...?

```//
//  Program to convert temperature from Celsius degree
//  units into Fahrenheit degree units:
//  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 Celcius:";
cin >> celsius;

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

// use conversion factor to convert Celsius
// to 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;
}```

### #2 groovicus

groovicus

• Security Colleague
• 9,963 posts
• OFFLINE
•
• Gender:Male
• Location:Centerville, SD
• Local time:07:26 AM

Posted 20 September 2008 - 11:50 AM

I just see one typo. You have a period where there should be a comma. I bet the error messages told you something along those lines.

### #3 Kanye

Kanye
• Topic Starter

• Members
• 97 posts
• OFFLINE
•
• Gender:Male
• Local time:08:26 AM

Posted 20 September 2008 - 01:31 PM

These are the errors that keep coming up:

```/Documents and Settings/Drew Reynolds/My Documents/CPP_Programs/Conversion.cpp C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\C cstdio: No such file or directory.
/Documents and Settings/Drew Reynolds/My Documents/CPP_Programs/Conversion.cpp C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\C cstdlib: No such file or directory.
/Documents and Settings/Drew Reynolds/My Documents/CPP_Programs/Conversion.cpp C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\C iostream: No such file or directory.
C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp In function `int main(int, char**)':
14 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp `cout' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)
14 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp stray '\223' in program
14 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp `Enter' undeclared (first use this function)
14 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp parse error before `temperature'
14 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp stray '\224' in program
15 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp `cin' undeclared (first use this function)
25 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp stray '\223' in program
25 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp `Fahrenheit' undeclared (first use this function)
25 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp parse error before `is'
25 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp stray '\224' in program
26 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp `endl' undeclared (first use this function)
29 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp stray '\223' in program
29 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp stray '\224' in program
29 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp `PAUSE' undeclared (first use this function)
29 C:\Documents and Settings\Drew Reynolds\My Documents\CPP_Programs\Conversion.cpp `PAUSE' undeclared (first use this function)```

### #4 Billy O'Neal

Billy O'Neal

Visual C++ STL Maintainer

• Malware Response Team
• 12,304 posts
• OFFLINE
•
• Gender:Male
• Location:Redmond, Washington
• Local time:06:26 AM

Posted 20 September 2008 - 04:51 PM

Your compiler is not setup correctly. It is reporting that it cannot find the standard header files on your machine. All of the other errors are caused by this code's reliance on those header files.

What compiler are you using?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)

### #5 Kanye

Kanye
• Topic Starter

• Members
• 97 posts
• OFFLINE
•
• Gender:Male
• Local time:08:26 AM

Posted 20 September 2008 - 10:24 PM

The compiler I use is mingw32. It's in it's own seperate folder within the Dev CPP folder right under my C drive. If anyone has Dev-C++ what compiler do you usually get with it? Should I download that one instead?

### #6 Billy O'Neal

Billy O'Neal

Visual C++ STL Maintainer

• Malware Response Team
• 12,304 posts
• OFFLINE
•
• Gender:Male
• Location:Redmond, Washington
• Local time:06:26 AM

Posted 20 September 2008 - 10:40 PM

Hmm.. DevCPP should have installed things alright. I would try Un and then Re installing DevCPP.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)

### #7 Romeo29

Romeo29

Learning To Bleep

• Members
• 3,194 posts
• OFFLINE
•
• Gender:Not Telling
• Location:127.0.0.1
• Local time:08:26 AM

Posted 21 September 2008 - 03:33 PM

```#include <iostream>

using namespace std;

int main(){

float temp;

cout << "Please type temperature in Celsius : ";

cin >> temp;

temp = temp*9.0/5.0+32.0;

cout << "Temperature in Fahrenheit is : " << temp;

return 0;

}```

### #8 Kanye

Kanye
• Topic Starter

• Members
• 97 posts
• OFFLINE
•
• Gender:Male
• Local time:08:26 AM

Posted 21 September 2008 - 05:45 PM

Before I go un and reinstall Dev C++ (again...) I was wondering if these pictures of my
Compiler Options would be of any value to those of you trying to help me. I appreciate the
help.

### #9 Glunn11

Glunn11

• Members
• 262 posts
• OFFLINE
•
• Gender:Male
• Location:Idaho
• Local time:07:26 AM

Posted 21 September 2008 - 06:12 PM

Simple error:

```// output the results (followed by a NewLine)
cout << "Fahrenheit value is:";
[b]cout << fahrenheit >> endl;[/b]```

The >> before endl; needs to be <<

### #10 Kanye

Kanye
• Topic Starter

• Members
• 97 posts
• OFFLINE
•
• Gender:Male
• Local time:08:26 AM

Posted 21 September 2008 - 09:41 PM

Are there any other C++ programs or compilers I should get. Because I've un and reinstalled Dev-C++ for the seventh time and it still doesn't work. My compiler still can't find iostream, cstdio or cstdlib in the directory. Are there any other options to download available to me?

Edited by Kanye, 21 September 2008 - 09:43 PM.

### #11 Romeo29

Romeo29

Learning To Bleep

• Members
• 3,194 posts
• OFFLINE
•
• Gender:Not Telling
• Location:127.0.0.1
• Local time:08:26 AM

Posted 22 September 2008 - 09:26 AM

In DEV-C++ you have to start a project and include files, then compile the project. Otherwise you get these errors.

You can use CodeBlocks which uses mingw port of GCC. Just start a new file type code and compile in it.

Hope it suseful info.

### #12 Kanye

Kanye
• Topic Starter

• Members
• 97 posts
• OFFLINE
•
• Gender:Male
• Local time:08:26 AM

Posted 22 September 2008 - 12:55 PM

Does that mean before I can use the #include statement, I need to include those files in my settings first?

### #13 Romeo29

Romeo29

Learning To Bleep

• Members
• 3,194 posts
• OFFLINE
•
• Gender:Not Telling
• Location:127.0.0.1
• Local time:08:26 AM

Posted 22 September 2008 - 04:50 PM

In Dev-C++ start a new project. Type your code and compile it.

What I am thinking, is that you are not starting a new project but just typing in a C++ file and trying to compile it.

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users