Hmm i put a conversion code and compile it i open the msdos .cpp file and i type in number and it automatically closes dos... its suposed to convert the code heh
Time to learn C++.
For one, the Window should close. You are NOT supposed to just double click it. It is a program run from command prompt.
To let you know:
#include <stdio.h> //Deprecate header file, use #include <cstdio>
#include <iostream.h> // Deprecate header file, use #include <iostream>
//Since you should use #include <iostream>, you are required to put the using namespaces directive
//afterwards so it would be 'using namespace sdt;' under the #includes
int main(int nNumberofArgs, char* pszArgs[])//The arguements arn't required when you arn't accepting arguments in the program
{
int nCelsius;
cout << "Enter the temperature in Celsius:"; //no where in the program do you use << endl;. This means
//the buffer never gets flushed. You should atleast use << endl; when you want a line to end
cin >> nCelsius; //fine for now, but you'll want to move to getline() eventually
int nFactor;
nFactor = 212 - 32; // fine but could be combined into 1 statement.
int nFahrenheit;
nFahrenheit = nFactor * nCelsius/100 + 32;
cout << "Fahrenheit value is:";
cout << nFahrenheit;
return 0; // return 0 is NOT required and shouldn't be used in C++ for the funciton main().
//main() will ALWAYS return an int and 0, so you can elide return 0;
}
- #include <stdio.h> //Deprecate header file, use #include <cstdio>
- #include <iostream.h> // Deprecate header file, use #include <iostream>
- //Since you should use #include <iostream>, you are required to put the using namespaces directive
- //afterwards so it would be 'using namespace sdt;' under the #includes
- int main(int nNumberofArgs, char* pszArgs[])//The arguements arn't required when you arn't accepting arguments in the program
- {
-
- int nCelsius;
- cout << "Enter the temperature in Celsius:"; //no where in the program do you use << endl;. This means
- //the buffer never gets flushed. You should atleast use << endl; when you want a line to end
- cin >> nCelsius; //fine for now, but you'll want to move to getline() eventually
- int nFactor;
- nFactor = 212 - 32; // fine but could be combined into 1 statement.
- int nFahrenheit;
- nFahrenheit = nFactor * nCelsius/100 + 32;
- cout << "Fahrenheit value is:";
- cout << nFahrenheit;
- return 0; // return 0 is NOT required and shouldn't be used in C++ for the funciton main().
- //main() will ALWAYS return an int and 0, so you can elide return 0;
- }
Revised version of your code:
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int nCelsius;
cout << "Enter the temperature in Celsius: ";
cin >> nCelsius;
int nFactor = 212 - 32;
int nFahrenheit = nFactor * nCelsius/100 + 32;
cout << "Fahrenheit value is: " << nFahrenheit << endl;
system("PAUSE");
}
- #include <cstdio>
- #include <iostream>
- using namespace std;
- int main()
- {
-
- int nCelsius;
- cout << "Enter the temperature in Celsius: ";
- cin >> nCelsius;
- int nFactor = 212 - 32;
- int nFahrenheit = nFactor * nCelsius/100 + 32;
- cout << "Fahrenheit value is: " << nFahrenheit << endl;
- system("PAUSE");
- }
See how much cleaner that is? Also, if you don't want to transverse the directories in command prompt to run your program from command prompt, #include <cstdio> in your program, then use system("PAUSE"); in your code when you want the program to stop so you can view the output.
I would recommend using a new book and maybe finding a new tutorial online, which is usually hard to find.
Btw how hard is c++ to learn :/ lol for a 16 year old that is.
C++ is an easy language. Once you learn the syntax, it isn't difficult at all. Some code may look complex as hell, but it usually isn't and once you get a grasp of things, you can understand it.
C++ is actually one of the easier languages.