PDA

View Full Version : C++ Help


JosefBud
09-23-2004, 01:40 AM
I got a C++ for dummies book and I have this code for it.. The program is on the CD it came with, but it was also in the book so I copied into my own. The one on the CD runs perfectly, but mine is poopy. I'm using Dev-C++. Here's the code:

//
// Program to 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 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;
}

and this is the log:

Compiler: Default compiler
Executing g++.exe...
g++.exe "D:\Dev-Cpp\Conversion.cpp" -o "D:\Dev-Cpp\Conversion.exe" -I"D:\Dev-Cpp\include\c++\3.3.1" -I"D:\Dev-Cpp\include\c++\3.3.1\mingw32" -I"D:\Dev-Cpp\include\c++\3.3.1\backward" -I"D:\Dev-Cpp\lib\gcc-lib\mingw32\3.3.1\include" -I"D:\Dev-Cpp\include" -L"D:\Dev-Cpp\lib"
D:/Dev-Cpp/Conversion.cpp: In function `int main(int, char**)':
D:/Dev-Cpp/Conversion.cpp:13: error: `cout' undeclared (first use this
function)

D:/Dev-Cpp/Conversion.cpp:13: error: (Each undeclared identifier is reported
only once for each function it appears in.)

D:/Dev-Cpp/Conversion.cpp:14: error: `cin' undeclared (first use this function)

Execution terminated

BioComputer
10-25-2004, 08:50 PM
using namespace std;

you have to add aline before int main , "every time "
using namespace std;

if you want my advice try to use microsoft visual C++ , it is the best
best wishes
BioComputer

ChrisSunderland
02-06-2009, 05:09 PM
I got a C++ for dummies book and I have this code for it.. The program is on the CD it came with, but it was also in the book so I copied into my own. The one on the CD runs perfectly, but mine is poopy. I'm using Dev-C++. Here's the code:

//
// Program to 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 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;
}

and this is the log:

Compiler: Default compiler
Executing g++.exe...
g++.exe "D:\Dev-Cpp\Conversion.cpp" -o "D:\Dev-Cpp\Conversion.exe" -I"D:\Dev-Cpp\include\c++\3.3.1" -I"D:\Dev-Cpp\include\c++\3.3.1\mingw32" -I"D:\Dev-Cpp\include\c++\3.3.1\backward" -I"D:\Dev-Cpp\lib\gcc-lib\mingw32\3.3.1\include" -I"D:\Dev-Cpp\include" -L"D:\Dev-Cpp\lib"
D:/Dev-Cpp/Conversion.cpp: In function `int main(int, char**)':
D:/Dev-Cpp/Conversion.cpp:13: error: `cout' undeclared (first use this
function)

D:/Dev-Cpp/Conversion.cpp:13: error: (Each undeclared identifier is reported
only once for each function it appears in.)

D:/Dev-Cpp/Conversion.cpp:14: error: `cin' undeclared (first use this function)

Execution terminated

Yes i tend to agree here