Please send questions to
st10@humboldt.edu .
#include
#include "profit.h"
using namespace std;
/*--------------------------------------------------
Contract: main : void -> int
Purpose: example of using a count-controlled loop
to call profit 10 times, each time asking
the user to type in a ticket-price
Examples: it should ask the user 10 times to
enter a ticket-price, and then display
to the screen the profit for that ticket
price.
Compile this using:
g++ -o countEx1 countEx1.cpp profit.o revenue.o cost.o attendees.o
-----------------------------------------------------*/
int main()
{
// local variables
float tick_price;
int counter;
// this is the number of times I'd like the loop
// to go...
const int NUM_TIMES = 10;
cout << "Welcome to a tester for profit!" << endl;
cout << "...that uses a COUNT-CONTROLLED loop" << endl;
cout << endl;
// counter should be INITIALIZED to its initial value
counter = 0;
// let's format the profit nicely...
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
// ask the user for ticket-price's 10 times,
// showing them the resulting profit for each one.
// (notice that I started at 0, and continue
// while counter is LESS THAN the desired number ---
// this is not the ONLY pattern, but it is a
// useful habit to get into with ARRAYS...)
while (counter < NUM_TIMES)
{
cout << endl;
cout << "Enter ticket price #" << (counter+1) << ": ";
cin >> tick_price;
cout << "Profit for $" << tick_price;
cout << " is: $" << profit(tick_price) << endl;
// IMPORTANT: INCREMENT your counter!!
counter = counter + 1;
}
return 0;
}