Getting Numbers
Part of the Fundamentals section of Coddy's C++ journey — lesson 39 of 74.
Challenge
BeginnerNow that we have a welcome message, it's time to get the numbers for our calculations. In C++, we use the std::cin object to get input from the user. For our calculator, we need two numbers to perform operations like addition, subtraction, multiplication, and division.
Modify the given code to get two double numbers from the user and store them in variables named num1 and num2. Use std::cin to read the numbers. After getting the numbers, print them to the console using std::cout with the following format:
First number: [first number]
Second number: [second number]Try it yourself
#include <iostream>
int main() {
std::cout << "Calculator App" << std::endl;
return 0;
}All lessons in Fundamentals
4Operators Part 1
Arithmetic OperatorsModulo OperatorIncrement/DecrementPost Increment/DecrementArithmetic ShortcutsComparison OperatorsString Comparison3Variables Part 2
Type DeclarationNaming ConventionsRecap - Initialize VariablesType Casting Part 1Type Casting Part 26Decision Making
If StatementIf - ElseSwitch StatementConditional OperatorRecap - If ElseNested If - Else