timdog345 -1 Light Poster
void firstClass(int f);
void businessClass(int b);
void coachClass(char typeTicket);



int main()
{
	char type;
	
	cout<<"Please enter your which class you want to fly. (f=firstClass, b=businessClass, c=coach)";
	cin>>type;
	cout<<endl;
	
	//bad data check
	while (type != 'f' && type != 'F' && type != 'b' && type != 'B'&& type != 'c' && type != 'C' )
	{
		cout<<"Invalid choice, please enter your which class you want to fly. (f=firstClass, b=businessClass, c=coach)";
		cin>>type;
		cout<<endl;
	}

	coachClass(type);

	return 0;
}

void coachClass(char typeTicket)
{
	int amount;
	
	
	if (typeTicket == 'c' || typeTicket == 'C')
	{
		cout<<"Please enter how many tickets you want. "<<endl;
		cin>>amount;
		cout<<endl;
		cout<<"you need to pay $"<<amount*200<<endl;
	}
	else if	(typeTicket == 'b' || typeTicket == 'B')
	{
		businessClass(typeTicket);                         
		/*cout<<"Please enter how many tickets you want. "<<endl;
		cin>>amount;
		cout<<endl;
		cout<<"you need to pay $"<<amount*250<<endl;
		*/
	}
	else 
	{
		 firstClass(typeTicket);
		/*
		cout<<"Please enter how many tickets you want. "<<endl;
		cin>>amount;
		cout<<endl;
		cout<<"you need to pay $"<<amount*300<<endl;
		*/
	}

	
}

void businessClass(int typeTicket)
{
	int amount;

	cout<<"Please enter how many tickets you want. "<<endl;
	cin>>amount;
	cout<<endl;
	cout<<"you need to pay $"<<amount*250<<endl;
	
	firstClass(typeTicket);
}

void firstClass(int typeTicket)
{
	int  amount;
	
	cout<<"Please enter how many tickets you want. "<<endl;
	cin>>amount;
	cout<<endl;
	cout<<"you need to pay $"<<amount*300<<endl;
	

}

Dani AI

Generated

Solid first pass — the program branches correctly by class, but a few bugs and style problems make it fragile and hard to extend. Key issues in the posted code: prototypes and definitions use inconsistent parameter types (int vs char), implicit char→int conversions hide bugs, one class-handler calls another (so selecting business prints both business and first results), and ticket-request/printing logic is duplicated. Those symptoms are why similar programs unexpectedly ask for input twice or compute the wrong total.

A clearer pattern: normalize the class input (use std::tolower), map class → price in one place, validate the ticket count once, compute total in one place, and keep function signatures consistent. Prefer small pure helpers that return a price or status instead of having class functions perform I/O and call each other. Use named constants or a small container for fares so changing prices is trivial.

Example (concise, safer structure):

#include <iostream>
#include <cctype>
#include <iomanip>

int priceFor(char cls) {
    switch (std::tolower(static_cast<unsigned char>(cls))) {
        case 'f': return 300;
        case 'b': return 250;
        case 'c': return 200;
        default: return -1;
    }
}

int main() {
    char cls;
    std::cout << "Select class (f/b/c): ";
    if (!(std::cin >> cls)) return 1;
    int price = priceFor(cls);
    if (price < 0) { std::cerr << "Invalid class\n"; return 1; }

    int count;
    std::cout << "Number of tickets: ";
    if (!(std::cin >> count) || count <= 0) { std::cerr << "Invalid ticket count\n"; return 1; }

    std::cout << "Total: $" << std::fixed << std::setprecision(2)
              << static_cast<double>(price) * count << '\n';
}

Quick tips: always match prototypes and definitions; cast to unsigned char before calling std::tolower; validate numeric input (consider getline+stoi to detect non-numeric entries); keep I/O in main and logic in small testable helpers; replace magic numbers with named constants or a lookup for future features (discounts, seat limits, etc.).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.