Hello today im gonna show u guyz how to make a Calculator that which will basically only do +
But if u like u can allways change and if your skilled u can make it a chooseable thing, but this is my 2nd C++ tut ;D so hope u like it.
So heres the guide step by step:
1. Open C++ 2008 (Express)
2. Press New Project and call it something like Calculator +
3. Go and Add new item and choose C++ file (.cpp) and call it whatever u like. (i prefer "+" or "Calculator +" or just "Calculator"
4. Open and it and well get to the code.
5. First of all u will write this:
Code:
#include <iostream>
This is the "library that wich contains the codes were gonna use.
6. Now u write
Code:
using namespace std;
This will do so that we dont have to write "std::" before all of our couts and cins.
7. Now here comes the first part of the calculator.
Code:
int main()
{ int number1, number2, sum;
this means that this is the main function and that "{" means start on a code and the "number1, number2, sum;" means that we have just made our own empty codes but we will declare them soon.
8. This is where the actually calculator comes in.
Code:
cout << "Number 1!\n" << endl;
cin >> number1;
cout << "Number 2!\n" << endl;
cin >> number2;
This is where we make the calculator write "Number 1!" and u enter a number and it will then remember the number as number1 and when it asks "Number2!" u write the number2 and it will remember it as number2.
9. This is where we find the sum.
Code:
sum = number1 + number;
cout << "The Sum Is ; " << sum << endl;
the first part of this code finds out what the sum is, and the next part is just telling us "The Sum Is ; " and then i write the sum that the line before it just came up with.
10. End of the code.
Code:
cin.get();
cin.get();
return 0;
}
the cin.get(); makes the window stay open instead of having a window that closes when opened. we have to use it 2 times, since this code is a bit strong. and the "return 0;" means that the code aint gonna go further . for an example u could write "return 1;" in the middle of a code then the code would stop the part its in and return to part 1 (not part 0), and the "}" means an end statement of the code.
Full Code:
Code:
#include <iostream>
using namespace std;
int main()
{ int number1, number2, sum;
cout << "Number 1\n" << endl;
cin >> number1;
cout << "Number 2\n" << endl;
cin >> number2;
sum = number1 + number2;
cout << "The Sum Is : " << sum << endl;
cin.get();
cin.get();
return 0;
}
the red "+" is the thing u want to change if u want the program to dividide or multiply or minus. Use this list for help:
Minus = -
Plus = +
Multiply = *
Dividide = /
i dont really know any others.
Thanks for watching! //Caroe