| CMPSC 101 - Functions Worksheet #7 | Name - |
1. Draw a console window and show the expected output as precisely as possible.
#include <iostream>
using namespace std;
void addSome(int &, int);int main( )
{
int number = 0;
int amountToAdd = 3;
int total = 0;
addSome(number, amountToAdd);
cout << number << endl;
getUserInput(numBooks);
cout << number << endl;
cout << amountToAdd << endl;
return 0;
}// end of main
void addSome(int & amount, int add)
{
amount = amount + add;
add = 5;
}// end of addSome
2. Draw a console window and show the expected output as precisely as possible. Assume that the user inputs the number 5 when prompted to input the number of books.
#include <iostream>
using namespace std;void getUserInput(int & num);
int main()
{
int numBooks = 0;
getUserInput(numBooks);
cout << "You owe $" << numBooks * 9.00 << endl;
return 0;
}// end of mainvoid getUserInput(int & num)
{
do
{
cout << "How many books would you like to buy? ";
cin >> num;
}while (num >= 50);
}// end of getUserInput
3. Write a program that includes a function named checkNum that receives a parameter that is passed by reference. The function must contain a loop that prompts the user to input an integer between or including 1 and 10 and obtains that input. If the value is not between or including 1 and 10, the function should display the message "Try again". The loop in the function should keep prompting the user to input a number until he has successfully inputted an integer between or including 1 and 10. After the user has eventually inputted an integer between or including 1 and 10, the main function should display that number.