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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • Syntax:
A

cin&raquo_space; Variable;
OR
cin&raquo_space; Variable1&raquo_space; Variable2&raquo_space; Variable3 ….&raquo_space; VariableN;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly