Simple Calculator

Simple calculator

Make a program that takes 2 inputs, and outputs the sum of them.

Example

4 1.6
5.6

Answer

#include <iostream>

int main() {
	float input1, input2;
	std::cin >> input1 >> input2;

	std::cout << "sum: " << input1 + input2;
}

Collected in one line variation

#include <iostream>

int main() {
	float input1;
	float input2;
	std::cin >> input1;
	std::cin >> input2;

	std::cout << "sum: " << input1 + input2;
}

The requested input will vary between these 2 programs.

The first program uses 2 std::cin calls. The user will input 2 different inputs (each given by hitting enter).

The second program only uses one std::cin call. The user inputs one input with 2 numbers seperated with space.

If you were to create this type of program for itself you should include a line that tells the user what type of input the program expects.
std::cout << "Please enter 2 numbers to get the sum of them.\n" << "Use enter to seperate the numbers.";

or

std::cout << "Please enter 2 numbers to get the sum of them.\n" << "Use enter to seperate the numbers.";
Questions