I was given an assignment where i have to calculate and aoutput the ocst of airline tickets for different classes (business class, coach class, first class). Output the price from different funtions.

Here is what I have.....

int main ()
	{

	double firstClass, coachClass, businessClass;

	cout<<"Enter the price of coach class."<<endl;
	cin>>coachClass;

	businessClass = coachClass+200;
	firstClass = businessClass+500;

	return 0;
	}


	void firstClass, coachClass, businessClass;
	int businessClass ()
	{
	
	cout<<"The price of business class is "<<businessClass<<endl;
	
	
	return 0;
	}

	void firstClass, coachClass, businessClass;
	int firstClass ()

	{

	cout<<"The price of first class is "<<firstClass<<endl;

	return 0;
	}

What is the problem ?

You are almost there. If you calculate the prices in main but print them in another function, you must first pass the prices as arguments to each function, or the function will not know what to print. Also remember that two entities cannot have the same name, so the prices and the functions will need different names if you want to reference them all in main. Further, functions must be declared before their use, whether with a prototype or with the full definition:

#include <iostream>

void businessClass(double price);
void firstClass(double price);

int main()
{
  double coachClassPrice;

  std::cout << "Enter the price of coach class: ";
  std::cin >> coachClassPrice;

  businessClass(coachClassPrice + 200);
  firstClass(coachClassPrice + 700);
}

void businessClass(double price)
{
  std::cout << "The price of business class is " << price << std::endl;
}

void firstClass(double price)
{
  std::cout << "The price of first class is " << price << std::endl;
}

I read the title, and thought it was someone looking for help with fishing, but instead found someone fishing for help ;)

Haha, that's a good one, Salem. :)

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.