+ 1

Whats the simplest way to make this work?

Its a very simple multiplication calculator, im new to C++ and im curious is there an easier shorter way to do this code/make it work? Thxx --------------------------------------------------------------------------------------------------------- #include <iostream> int number; int number2; int main() { std::cout << "This is a multiplication calculator, insert your first number below.\n"; std::cin >> number; std::cout << "Please put in your second number.\n"; std::cin >> number2; number *= number2; std::cout << "Your answer is " << number << std::endl; return(0); } -----------------------------------------------------------------------------------------------------------

28th Jul 2017, 6:54 AM
Renny Kelvy
Renny Kelvy - avatar
2 Réponses
+ 8
you made number and number2 globals. this is not required and considered bad practise. Especially so when there is no need to do it. Move these variable inside main.
28th Jul 2017, 7:46 AM
jay
jay - avatar
0
And maybe you could get the numbers with one input and then split it...
28th Jul 2017, 7:14 AM
Dennik