Basic Operations
Part of the Fundamentals section of Coddy's C++ journey — lesson 40 of 74.
Challenge
BeginnerAdd the basic arithmetic operations (addition, subtraction, multiplication, and division) on num1 and num2. Store the results in variables named sum, difference, product, and division, respectively. Print the results to the console using std::cout in the following format:
Sum: [sum]
Difference: [difference]
Product: [product]
Division: [division]Try it yourself
#include <iostream>
int main() {
std::cout << "Calculator App" << std::endl;
// Get input from the user
double num1;
std::cin >> num1;
double num2;
std::cin >> num2;
// Print the numbers
std::cout << "First number: " << num1 << std::endl;
std::cout << "Second number: " << num2 << 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