Hey guys, im writing my first C++ program, and its working great(after some issues getting used to new ANSI rules, my books a bit outdated, have newer resources now), except for the fact that it automatically closes out. Its a simple program that converts celsius to fahrenheit(yea stupid i know, but i just started yesterday and ya gotta walk before you can crawl), anyways, heres the source code, was just wondering what i was missing on the end to make it stay up and display the results before immediately closing out, thanks for the help guys, and i look forward to being here and learning as much as possible!
//
// Program to convert temperature from Celsius degree
// units into Fahrenheit degree units:
// Fahrenheit = Celsius * (212-32)/100+32
//
#include <stdio.h>
#include <iostream>
;int main(int nNumberofArgs, char* pszArgs[])
{
//enter the temperature in Celsius
;int nCelsius;
std::cout << "Enter the temperature in Celsius:";
std::cin >> nCelsius;
no luck with the void pause gargoyle, im using visual C++ 2010 express atm, maybe an unrecognized command or am i just entering the code wrong?(entered it exactly as you wrote it there, maybe missing a ; before the void?)
im new to this too, but my experiences tell me that if you are using windows as the host OS, system("PAUSE") is a pretty easy way to do it. its a system call, so it can be a potential security risk, plus it takes unnecessary resources to execute, all-in-all it sucks and isnt a good idea. but for sheer simplicity, its easy to tack on at the end of your source code just for the purpose of testing.
plus system calls are not platform independent (system(anything) will not work the same on other host OS)
#include <iostream>
usingnamespace std;
// ............................................
void pause()
{
cout << "Press ENTER to continue\n";
cin.get();
}
// ......................... ^do that^
// ......................... then the rest of your program
int addition (int a, int b)
{
int r;
r=a+b;
return (r);
}
int main ()
{
int z;
z = addition (5,3);
cout << "The result is " << z;
return 0;
// .............
pause()
// ^ then this ^
}
usingnamespace std; after the includes is a useful line to add to just about any beginner's code. Eventually you get tired of writing std::cin.get, or std::cout...
I should also add that this site has a great tutorial, if you haven't seen it yet.