Hello fellow coders!
I'm currently learning C++ off Udemy and I decided to try something on my own and build a simple calculator. I shared the code down below, but what I want to know is what can I do to improve this code?
First, I declared three integers firstNum, secondNum and finalNum. Now, I need to gain input from the user I do this by using CIN (Character In) and have the user input placed into one of the integers I created at the beginning (
I'm currently learning C++ off Udemy and I decided to try something on my own and build a simple calculator. I shared the code down below, but what I want to know is what can I do to improve this code?
First, I declared three integers firstNum, secondNum and finalNum. Now, I need to gain input from the user I do this by using CIN (Character In) and have the user input placed into one of the integers I created at the beginning (
firstNum
& secondNum
). Then the compiler adds the two integers together and places the result into finalNum
.
C++:
#include <iostream>
int main() {
int firstNum;
int secondNum;
int finalNum;
std::cout << "Input first number" << std::endl;
std::cin >> firstNum;
std::cout << "Input second number" << std::endl;
std::cin >> secondNum;
finalNum = firstNum+secondNum;
std::cout << "Calculating..." << std::endl;
std::cout << finalNum << std::endl;
return 0;
}
Input first number
5
Input second number
5
Calculating...
10
Press any key to continue . . .
5
Input second number
5
Calculating...
10
Press any key to continue . . .