input Flashcards
1
Q
Interactive Input in C++
A
Uses “cin” and is used to retrieve information from the user
- Only uses variables to store data provided by the user
2
Q
- Syntax:
A
cin»_space; Variable;
OR
cin»_space; Variable1»_space; Variable2»_space; Variable3 ….»_space; VariableN;
3
Q
The variable used must match
A
the data that is expected (Ex. If you
request an int, then you must store the data in an int
4
Q
Interactive input requires TWO STEPS:
A
- Request (uses cout) => Provide a detailed request to the user
asking for a specific piece of information.
- Response (uses cin) => Read the data provided by the user
and store it in the variable provided.
5
Q
When using a cin statement
A
the cursor will sit and wait
for you to provide input. After the data is entered,
you must press the “Enter” key to proceed
6
Q
//Write a program to ask for two numbers and multiply them //Show the result as * =
A
//1) Declare variables double n1 = 0; double n2 = 0; double prod = 0;
//2) Assign values to the variable (from the user) cout << "What is the first number? "; //Request cin >> n1; //Response cout << "What is the second number? "; //Request cin >> n2; //Response
//3) Calculate product prod = n1 * n2;
//4) Output cout << n1 << " * " << n2 << " = " << prod << endl;