#include <iostream>
using namespace std;
int main()
{
//define price for person
const unsigned short PRICE = 7;
//define age for full price
const unsigned short ADULT_AGE = 18;
//define minimal possible age
const unsigned short MIN_AGE = 0;
//define maximal possivle age
const unsigned short MAX_AGE = 110;
int peopleNum;
double total = 0;
//input people number and check if this number is more than 0
cout << "Input number of people:" << endl;
cin >> peopleNum;
while (peopleNum < 1) {
cout << "incorrect people number: at least 1 is required. Input again" << endl;
cin >> peopleNum;
}
//get age of each person
int i = 0;
while (i < peopleNum) {
short age;
cout << i+1 << " person. Input age:" << endl;
cin >> age;
//check if it is possible age
if (age < MIN_AGE || age > MAX_AGE) {
cout << "person age should be more or equal " << MIN_AGE << " and less or equal " << MAX_AGE << endl;
continue;
}
//check if discount is needed and add price
else if (age < ADULT_AGE) total += PRICE/2.0;
else total += PRICE;
++i;
}
//output result
cout << "amount to be charged: " << total << "$" << endl;
}
Comments
Leave a comment