Ok, this is a web designers forum, but who says people aren't open to learning new things. This tutorial is pretty beginner for C++, it would help if you new a little, but you don't have to if you aren't planning on actually learning it and using it alot.
Anyways, I got this tutorial out of a book that I have, and I kind of re wrote it a little to make it little easier to understand.
First, in order to do this, you must have a C++ compiler and you can get a pretty good free one HERE
Now, the program we are going to create does a simple conversion of Celsius degrees, to Fahrenheit degrees. It is kind of dumb, but it guess if you have some home work and you get something like this and arent' good with converting temps, you always have this.
First, open up your compiler, and go file>new>source file
NOTE: I am just going by the Dev-C++(the compiler I linked you to) comands and buttons. It may be different if you have a different compiler.
Next we should add some comments at the top of the new file so if we ever go back to it, we know what it was supposed to do. So:
Code:
// Program converts temperature from Celsius degrees
// to Fahrenheit dregrees
// the equation is Celsius * (212 - 32)/100 + 32
Ok, that little snippet was just comments, when your computer is processing the program, it will just ignore those lines. and line beginning with a // is a comment. There will be a few of those inside the program. So watch for them.
Now we need to do the includes and stuff, it tells your computer the type of program it will be and what kind of things will be done. Kind of hard to explain. you can look it up if you want a good description.
Code:
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
Don't forget the semi colon at the end. That can be so frustrating when all you forget is that and your searching for hours trying to find out what is wrong. Like any modern programming or scripting language.
Now we need to give some integers.
Code:
int main(int nNumberofArgs, char* pszArgs[])
{
Ok all that does is give an integer and kind of a variable which I think we will call to later on in the program. That bit doesn't do much. Now lets add some interactivity to the program. So that the user can input values. Nothing much really. but, ehh, its a simple program right?
Code:
// enter the temp in Celsius
int celsius:
cout << "Enter The Temperature in Celsius:";
cin >> celsius:
COUT stands for See Out, and CIN stands for See In. Cout is the part that will be displayed on the program, which is in the quotes.
the CIN, will output the value that you enter into the program. So basically like typing into notepad or Word. It will just display whatever you type.
Now time to put the equation into the whole thing so that it calculates it all and converts it.
Code:
// conversion equation for the program
int fahrenheit;
fahrenheit = factor * celsius/100 + 32;
Ok, the int is basically a variable, but not quite, in later tutorials I will go over more and teach more advanced things. See how we call to it in that little bit? and the * which I call a "splat" is the sign for multiplication, and the / is the division sign. Thats pretty understandable. Now time to display the conversion and the final answer and end the program. I will explain this last bit in a second.
Code:
// output the answers
cout << "Fahrenheit value is:";
cout << fahrenheit << endl;
// wait until user is ready before terminating program so he/she can see the answer
system("PAUSE");
return 0;
}
All that does is display the converted value, the the system pause displayes a messsage saying "Press any key to exit program" or something like the return 0; ends the program, and the closing bracket closes the one after we declared the first integers.
Ok, thats my tutorials. I hope it was understandable. If you need any help with anything just ask me.
EDIT, to compile it and test it, you need to save the the program as whatever you want, then go to Execute>Compile
It will run through your whole code and check for errors, then it will say done when it is finished.
As long as you type all the code shown in order into your compiler it will work, then you go execute>run and a Command Prompt window will open with your program.
All credits to :
http://forums.tizag.com/showthread.php?s...4c3&t=1125