Code:
#include <iostream.h>
#include <iomanip.h>
const int NAME_LEN = 25;
const int DATE_LEN = 11;
const int BUFFER_LEN = 11;
using namespace std;
// Paintball assignment. A program to produce quotes
// for customers of a paintball company
int main()
{
int final_cost;
int paintball_total;
int group_size; // size of the group
int duration; // length of times in hours
float charge; // charge for the booked session
int paintballs = 20; //each player gets 20 free per hour
float perioda = 2.60f; // £2.60 per hour if playing less than or equal to 2 hour
float periodb = 2.30f; // £2.30 per hour if playing between 3 and 5 hours
float periodc = 2.10f; // £2.10 per hour if playing for 6 or 7 hours
float periodd = 2.00f; // £2.00 per hour if playing between 8 or 10 hours
int ballsa = 0; // groups upto 10 members get no bonus balls
int ballsb = 50; // groups between 11 and 15 get 50 bonus balls
int ballsc = 100; // groups between 16 and 20 get 100 bonus balls
int ballsd = 160; // groups between 21 and 25 get 160 bonus balls
int ballse = 250; // groups between 26 and 30 get 250 bonus balls
char gear; // users answer Y or N to equipment hire
char extra; // users answer Y or N to extra paintballs
int extra_balls=0; // how many balls does the user want
int balls_total=0; //
char name[NAME_LEN];
char date;
char buffer[BUFFER_LEN];
char book_again;
cout << "Please enter name - Initial and Surname ";
fflush(stdin);
cin.getline(name, NAME_LEN);
cout << endl;
do {
cout << "Please enter the date of the booking (DD/MM/YYY) ";
cin.getline (buffer, BUFFER_LEN);
cout << endl;
} while (strlen(buffer) !=10);
do {
// this section specifies group size
cout << "Enter group size (30 being the max): ";
cin >> group_size;
cout << endl;
if (!(group_size >= 1 && group_size <= 30))
{
cout << "Invalid group size, Please enter 1 to 30";
cout << endl;
}
} while (!(group_size >= 1 && group_size <= 30));
do {
// this section specifies game duration
cout<< "How long do you want to play (1 to 10 hours)?: ";
cin>> duration;
cout<< endl;
if (!(duration >= 1 && duration <= 10));
{
cout << endl;
}
} while (!(duration >= 1 && duration <= 10));
if (duration <= 1)
{
charge = perioda * (group_size * duration);
}
else if (duration >=2 && duration <=5)
{
charge = periodb * (group_size * duration);
}
if (duration >5 && duration <=7)
{
charge = periodc * (group_size * duration);
}
else if (duration >7 && duration <=10)
{
charge = periodd * (group_size * duration);
}
cin.ignore();
{ // this section works out the cost for specified session
cout<< "The session you have specified will cost: \234" << charge;
cout<< endl;
cin.ignore();
}
{ // this section works out how many free paintballs the group will receive
if (group_size <=10) {
paintballs = (paintballs*(group_size*duration))+ ballsa;
}
else if (group_size >10 && group_size <=15) {
paintballs = (paintballs*(group_size*duration))+ ballsb;
}
else if (group_size >15 && group_size <=20) {
paintballs = (paintballs*(group_size*duration))+ ballsc;
}
else if (group_size >20 && group_size <=25) {
paintballs = (paintballs*(group_size*duration))+ ballsd;
}
else if (group_size >25 && group_size <=30) {
paintballs = (paintballs*(group_size*duration))+ ballse;
}
cout<< "You will receive "<< paintballs <<" free paintballs for your game.";
cin.ignore();
cout<< endl;
}
{ //this section asks the user if they wish to hire equipment
do {
cout<< "Do you need to hire equipment at a charge of \2345 per group? (Y/N): ";
cin>> gear;
} while (gear!='N' && gear != 'n' && gear!='Y' && gear!='y');
if (gear == 'N' || gear == 'n' ) {
cout<< "Thankyou. You have chosen not to hire any equipment.";
cin.ignore();
cout<< endl;
cout<< endl;
}
else if (gear == 'Y' || gear == 'y') {
cout<< "Thankyou. You have chosen to hire equipment. This session will cost: \234"
<<charge +5;
cin.ignore();
cout<< endl;
cout<< endl;
}
}
{ // this section asks the user if they wish to buy more balls
do {
cout<< "Do you want any more paintballs at 100 for \2346 (Y/N): ";
cin>> extra;
} while (extra !='n' && extra != 'N' && extra !='Y' && extra !='y');
if (extra == 'N' || extra == 'n') {
cout<< "Thankyou. You have requested NO extra paintballs";
cout<< endl;
cin.ignore();
}
else if (extra == 'Y' || extra == 'y') {
cout<< "Thankyou. How many extra packets of paintballs would you like?: ";
cin>> extra_balls;
balls_total = extra_balls*6;
cout<< "Thankyou. "<<extra_balls<<"packets will cost you: \234" <<balls_total;
cin.ignore();
cout<< endl;
}
}
{
final_cost = balls_total + charge;
cout<< "The total charge for this session will be \234"<<final_cost<<", thankyou.";
cout<< endl;
cout<< endl;
cout<< endl;
}
{
paintball_total = paintballs + (extra_balls*100);
}
{
cout << "---------------------------------------------------------------------------- " <<endl;
cout << " Name | Date | Duration | Group | Equipment | Total | Total | " <<endl;
cout << " | | | Size | Hire | Paintballs | Cost | " <<endl;
cout << "---------------------------------------------------------------------------- " <<endl;
cout << setw(10)<< name;
cout << setw(12)<< buffer;
cout << setw(7) << duration;
cout << setw(10)<< group_size;
cout << setw(7) << gear;
cout << setw(15) << paintball_total;
cout << setw(11) << final_cost;
cout<< endl;
cout << "---------------------------------------------------------------------------- " <<endl;
cout<< endl;
cout<< endl;
}
do {
cout<< "Would you like to book another session? (Y/N): ";
cin>> book_again;
cout<< endl;
} while (book_again ='y' && book_again ='Y' && book_again ='n' && book_again ='N');
if (book_again == 'N' || book_again == 'n') {
system("pause");
}
else if (book_again == 'Y' || book_again == 'y') {
return 0;
}
}
and there it is.
i see the end part as:
output 'do you want to book again' until user choses Y/y or N/n. specifying Y/y should then return the user to start of program. specifying N/n should stop the program...
i can't get my head round it! it's something so simple and it's had me baffled for a good 45 mins. now that's hardcore stupidity in my books.