Circuit Negma

C++, C, VB.NET, PCB, Electronics, Circuit Design

Movie Calculator

Posted by Circuit Negma on March 17, 2006


/*
 *  Copyright © 1997-2003 Metrowerks Corporation.  All Rights Reserved.
 *
 *  Created By: Circuit Negma
 *
 *  Date      : March 17, 2006
 *
 *  File      : ch3_movie.cpp
 *
 *  Decription: Movie Ticket Sale and Donation to Charity.
 *
 */

#include <iostream>
#include <iomanip>	// to use setfill(car) Function.
using namespace std;

	// Define Function iCheck() to check for integer numbers.
	int iCheck()
	{
		bool flag;
		int i;
		
	//	cin.clear();
 	//	cin.ignore(500, '\n');
 	
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
		
		    
	    return i;

	}
	
	// Define Function dCheck() to check for double numbers.
	double dCheck()
	{
		bool flag;
		double i;
		
	//	cin.clear();
 	//	cin.ignore(500, '\n');
 	
 		flag = cin >> i;
 
		 while (!flag)
		 {
		       cout << endl;
		       cin.clear();
		       cin.ignore(500, '\n');
		       cout << "this is not a number" << flush << endl;
		       cout << "please enter a number again: " << flush;
		       flag = cin >> i;
		       
		}
	    
	    return i;

	}


//***************************************************************

//***************************************************************
//***************** Build in Function main() ********************

int main()
{
	// Declare input variables
	string  movieName;
	double  AdultTicketPrice, ChildTicketPrice;
	int		noOfAdultTicketSold, noOfChildTicketSold;
	int		totalnoOfTickets;
	double	percentDonation;
	double	grossAmount;
	double	amountDonated;
	double	netSaleAmount;
	
	
	// Main Program
	
	cout << fixed << showpoint << setprecision(2);	
	
	cout << setw(30) << setfill('*') << " Welcome to Movie Theater " << flush;
	cout << setw(5)	 << " " << endl;
	cout << endl;
	
	cout << "Please, Enter movie name: " << flush;
	getline(cin, movieName);
	cout << endl;
	
	cout << "Please, Enter the price of an Adult ticket: " << flush;
	AdultTicketPrice = dCheck();
	cout << endl;
	
	cout << "Please, Enter the price of an Child ticket: " << flush;
	ChildTicketPrice = dCheck();
	cout << endl;
	
	cout << "Please, Enter number of adult tickets sold: " << flush;
	noOfAdultTicketSold = iCheck();
	cout << endl;
	
	cout << "Please, Enter number of child tickets sold: " << flush;
	noOfChildTicketSold = iCheck();
	cout << endl;
	
	cout << "Please, Enter the percentage of donation: " << flush;
	percentDonation = dCheck();
	cout << endl << endl;
	
	
	// Calculations and Results
	
	totalnoOfTickets = noOfAdultTicketSold + noOfChildTicketSold;
	grossAmount		 = (AdultTicketPrice * noOfAdultTicketSold) + (ChildTicketPrice * noOfChildTicketSold);
	amountDonated	 = grossAmount * percentDonation / 100;
	netSaleAmount	 = grossAmount - amountDonated;
	
	// Print out the Results
	
	cout << "_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*_*" << flush << endl;
	cout << left;
	
	cout << setw(35) << setfill('.') << "Movie Name: " 
		 << right << " " << movieName << endl;
	
	cout << setw(35) << left << "Number of Tickets Sold: "
		 << right << setfill(' ') << setw(10) << totalnoOfTickets << endl;
	
	cout << setw(35) << left << setfill('.') << "Gross Amount: "
		 << right << " $" << setfill (' ') << setw(8) << grossAmount << endl;
		 
	cout << setw(35) << left << setfill('.') << "Percentage of Gross Amount Donated: "
		 << right << setfill (' ') << setw(9) << percentDonation << "%" << endl;
		 
	cout << setw(35) << left << setfill('.') << "Amount Donated: "
		 << right << setfill(' ') << " $" << setw(8) << amountDonated << endl;
		 
	cout << setw(35) << left << setfill('.') << "Net Sale: "
		 << right << setfill(' ') << " $" << setw(8) << netSaleAmount << endl;
		
	return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: