Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++: Write a program that computes the total cost for the number of cell phon

ID: 3803779 • Letter: I

Question

In C++:

Write a program that computes the total cost for the number of cell phones bought at a store. Define two variables, numofCellPhones and costPerCellPhone inside the main function and initialize them to zero. Now, define a new function ReadUserInput that takes these two variables as reference parameters and asks the users to enter non-zero positive values (input validation) for them. Finally, back in main function compute the total cost of the cell phone purchase and print it on the console.

You MUST use references

Example (do not print lines surrounded by ****):

****INSIDE Main, Calling ReadUserInput****

****INSIDE ReadUserInput****

How many cell phones did you buy? 7

What is the cost of each cell phone? 900

**** INSIDE MAIN ****

You bought 7 cell phones at $900 each, and the total cost is = $6300

Explanation / Answer

#include<iostream>
using namespace std;

int main()
{
   int numofCellPhones = 0, costPerCellPhone = 0;
   void ReadUserInput(int &numofCellPhones, int &costPerCellPhone);
   //call function ReadUserInput
   ReadUserInput(numofCellPhones, costPerCellPhone);
   cout << "You bought " << numofCellPhones << " cell phones at $" << costPerCellPhone << " each, and the total cost is = $" << numofCellPhones*costPerCellPhone << endl;
}

void ReadUserInput(int &numofCellPhones, int &costPerCellPhone)
{
   cout << "How many cell phones did you buy? ";
   cin >> numofCellPhones;
   cout << "What is the cost of each cell phone? ";
   cin >> costPerCellPhone;
}

------------------------------------------------------------------------------------------

//output

How many cell phones did you buy? 7
What is the cost of each cell phone? 900
You bought 7 cell phones at $900 each, and the total cost is = $6300