SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
C++ Basics
Exercise:
Self-test Exercises
Question:9 | ISBN:9780321531346 | Edition: 7

Question

Give an input statement that will fill the variable the_number (of type int) with a number typed in at the keyboard. Precede the input statement with a prompt statement asking the user to enter a whole number.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

The following "cout" statement is used to a prompt statement asking the user to enter a whole number and "cin" input statement that will read the variable the_number (of type int) with a number typed in at the keyboard:

int the_number;
cout <<"Enter a whole number and press return: ";
cin >> the_number;

Complete executable program code:

#include <iostream>
using namespace std;

int main()
{ 
    //Declare the variable name, 'the_number'
    //along with the data type is int
    int the_number;

    //Prompt input statement as asking the user 
    //to enter a whole number.
    cout <<"Enter a whole number: ";

    //Read input from the user
    cin >> the_number;
    return 0;
}

Output of the program code:

Note: Only read the input value from the user by promptin of statement.

Enter a whole number: 500

 

0 0

Discussions

Post the discussion to improve the above solution.