First, please always use code tags. Edit your post, select all the code, then press the <> button on the right under the format menu.
Also, in your IDE make the indenting spaces (4 spaces say) not tabs, it will display better on this page, because tabs get translated to 8 spaces here.
If you do this, your code should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
// other system includes here
// your own header files #included here
using namespace std; // don't do this
// put function declarations here
// try to list them in the same order as they are called in main()
int main ()
{
// don't declare more than 1 variable per line
int a, b; // (this is called declaration of varables)
// use meaningful names
// The specification said ints, but
// double gives more flexibility - can do division for example
// you can leave it as ints if you want
double FirstNumber = 0.0; // always initialise variables with something preferably here at declaration
double SecondNumber = 0.0; // Zero might not always be a good choice however
// put spaces around operators - don't jam everything together
// use // for comments
std::cout << "Enter any 2 numbers \n"; // (" " will display in the sceen; \n for new line)
std::cin >> a >> b;
std::cout << "the sum of numbers you have entered is equal to" << (a+b) << std::endl;
std::cout<<"the product of the numbers you have entered is equal to"<<(a*b)<<std::endl;
return 0;
} // end of main
// put function definitions here
// try to list them in the same order as they are called in main()
|
Although this might seem trivial now, the code for getting the input, doing the sum, and the product could be in functions of their own. If you added a lot of functions later this makes more sense.
The
using namespace std;
thing is bad, because it brings in the whole std namespace, polluting the global namespace, which can cause naming conflicts for variables and functions. Did you know that
std::distance
,
std::left
and
std::right
exist in the std namespace? If you had a function or variable with that name and had
using namespace std;
, then you will have big problems.
I realise you are a brand new beginner, just trying to introduce some good habits early on - and give some ideas for the future. Hope all goes well - and Good Luck !! :+)