Question

In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

In this program, you will be using C++ programming constructs, such as functions.

main.cpp

Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user.

Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller.

Your main () function will call the function getInteger and will then display the value returned by that function.

Input Validation

You can either assume the user will always input a valid integer, or you can add input validation for the integer similar to the example shown in the midterm solution.

Hints

Be sure and define the function prototype before main () calls it.

Don't forget to add comments to explain what the code is doing and where control of the program is executing.

Choose variable names and function names that describe the purpose of the variable.

Sample Output

Enter an integer: 7

You entered 7

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;
//function prototype
int getInteger();
int main(){
//calling getInteger function to read integer value from user
   cout<<"You entered "<<getInteger();
}
//function to read integer from the user
int getInteger(){
//declared integer variable
   int n;
   //asking user to enter int value
   cout<<"Enter an integer: ";
   cin>>n;
   //returing the int value to user
   return n;
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Is Prime Number In this program, you will be using C++ programming constructs, such as functions....

    Is Prime Number In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter a positive integer, and outputs a message indicating whether the integer is a prime number. If the user enters a negative integer, output an error message. isPrime Create a function called isPrime that contains one integer parameter, and returns a boolean result. If the integer input is a prime number, then this function returns...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • You are to write a program IN C++ that asks the user to enter an item's...

    You are to write a program IN C++ that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: if the an item's wholesale cost is 5.00 and its markup percentage is 100%, then the item's retail price is 10.00 If an item's wholesale cost is 5.00 and its markup percentage is 50%, then the item's retail price is 7.50 Program design specs. You should have 5...

  • Write a C++ program that uses: .selection constructs (if, if else, and switch) .multiway branches .looping...

    Write a C++ program that uses: .selection constructs (if, if else, and switch) .multiway branches .looping constructs (do and while loops) .Boolean expressions, bool and char types. 1. Develop a program that calculates charges for an Internet provider. The cost is determined by the amount of data used and the consumer plan. Package B (basic) is the most affordable if you plan on using < 20GB (20,000MB), however, if you consume more than 20GB (20,000MB) you are charged for each...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • C++ programming For this assignment, write a program that will act as a geometry calculator. The...

    C++ programming For this assignment, write a program that will act as a geometry calculator. The program will be menu-driven and should continue to execute as long as the user wants to continue. Basic Program Logic The program should start by displaying a menu similar to the following: Geometry Calculator 1. Calculate the area of a circle 2. Calculate the area of a triangle 3. Quit Enter your choice(1-3): and get the user's choice as an integer. After the choice...

  • In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

    In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...

  • a. Ask the user for the input of a letter (char type). Write a function that...

    a. Ask the user for the input of a letter (char type). Write a function that takes a char as the argument (parameter) and returns the ASCII value of that char back to the caller. Call the function using the char variable and taking input from the user (no validation required). Display the value in ASCII. b. Write a program that takes a char as the argument (parameter) and uses a loop to interrogate the char, calling a function that...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Modular program mathlab: Write a program in Matlab that would continuously ask the user for an...

    Modular program mathlab: Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “You got it” If the user’s die is smaller, it should display, “Nice try” If the results are the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT