Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

My compiler fails to build this code correctly; I can't see an issue. Can someone help me debug it?

#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main (int nNumberofArgs, char* pszArgs[])
{
    //Enter temperature in Celsius
    int celsius;
    cout << "Enter the temperature in degrees Celsius";
    cin >> celsius;

    //convert Celsius into Fahrenheit
    int fahrenheit;
    fahrenheit = celsius * 9/5 + 32;

    //display result and line break
    cout << "Fahrenheit value is: "; 
    cout << fahrenheit ;

    return 0;
}
share|improve this question
1  
What do you mean "Fails to build this correctly" – Loki Astari Jun 6 '12 at 20:26
What is the error you get? – rahul Jun 6 '12 at 20:27
Works fine with Visual Studio 2010 Ultimate. What compiler are you using and with what version of C++? – Casey Jun 6 '12 at 20:50
1  
The question is missing lots of relevant information (what error, notably) and it’s posted on the wrong site: this site is for code reviews of working code. – Konrad Rudolph Jun 6 '12 at 21:51
I'm not actually getting any errors. Xcode (my compiler) just displays a message saying, "build failed". Not even a red exclamation mark next to a line. And as for the fact that this is on the wrong site, sorry, but if you could point me towards the right one, I'd be very grateful. – Jules Mazur Jun 7 '12 at 0:30

closed as off topic by Brian Reichle, Winston Ewert Jun 6 '12 at 23:51

Questions on Code Review Stack Exchange are expected to relate to code review request within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

up vote 3 down vote accepted

Stop doing this it is a bad habbit the will cause problems in bigger programs.

using namespace std;

Anything from the standard namespace just prefix with std::. If you are uisng a particular item a lot (like cout) then you can pull it individually with using std::cout.

The traditional way to declare main is

int main (int nNumberofArgs, char* pszArgs[])

// usually looks like this
int main(int argc, char* argv[])

Prefer to declare and initialize in a single line

int fahrenheit;
fahrenheit = celsius * 9/5 + 32;

// Prefer:
int fahrenheit = celsius * 9/5 + 32;

Main is special.
If you don't explicitly return anything the the compiler will add return 0 to your code. Thus if your application never returns anything different then don't use it. This is a way to indicate there is no error state in your applicaiton (it always works).

return 0;
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.