Parrot Program

Parroting program

Make a program that takes 3 floats and outputs them back to the user. Seperate the numbers with commas.

Example

4 1.6 3.2
4, 1.6, 3.2

Answer

Alternative 1:

#include <iostream>

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

	std::cout << input1 << ", " << input2 << ", " << input3;
}

Collected in one line variation

#include <iostream>

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

	std::cout << input1 << ", " << input2 << ", " << input3;
}

The requested input will vary between these 2 programs.

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

The second program only uses one std::cin call. The user inputs one input with 3 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 3 numbers to get them in return.\n" << "Use enter to seperate the numbers.";

or

std::cout << "Please enter 3 numbers to get them in return.\n" << "Use enter to seperate the numbers.";
Questions