1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// basics/c2f.cpp - Convert Celsius to Fahrenheit
// Fred Swartz, 2003-10-26 // (1)
#include <iostream> // (2)
using namespace std; // (3)
int main() { // (4)
float celsius; // (5)
float fahrenheit;
cout << "Enter Celsius temperature: "; // (6)
cin >> celsius;
fahrenheit = 1.8 * celsius + 32;
cout << "Fahrenheit = " << fahrenheit << endl;
system("PAUSE"); // only Dev-C++ // (7)
return 0; // (8)
}
|
#include statements make standard libary functions available.using namespace std statement allows access to
standard library names (eg, cin and cout)
without a prefix (std::cin and std::cout).main() function.
There is an alternate way to declare main, but we will use
this simple style.main() function is declared to return an int,
therefore it must return some integer value.
Zero is commonly used to indicate that the program terminated successfully, but
the system normally ignores this number.