help me

// A PROGRAM FOR PASSENGER FARE, THE SYSTEM MUST ASK THE USER TO ENTER AGE OF PASSENGER.IF AGE IS BELOW 12,THERE IS A 10% DISCOUNT, ELSE 5% DISCOUNT
// THE USER WILL NOW ENTER THE DESTINATION CODE TO COMPUTE THE FARE.
// CODE FARE
// CHINA 2500
// JAPAN 3000

#include <iostream>
#include <string>
using namespace std;
int main()
{
int age,china_fare,japan_fare;
double discount,discounted_fare;
char destination;
japan_fare=3000;
china_fare=2500;
cin>>age;
cin>>destination;
if (destination=japan_fare)(age>12)
discount=japan_fare*0.10;
discounted_fare=japan_fare-discount;
else if (destination=japan_fare)(age<12)
discount=japan_fare*0.05;
discounted_fare=japan_fare-discount;
else if (destination=china_fare)(age>12)
discount=china_fare*0.10;
discounted_fare=china_fare-discount;
else if (destination=china_fare)(age<12)
discount=china_fare*0.05;
discounted_fare=china_fare-discount;
cout<<age<<discount<<destination;
system ("pause");
return 0;
}

what is wrong with my prog.
use code tags mate.

Firstly try and use braces around your if/else stuff.

This
 
if (destination=japan_fare)(age>12)


looks wrong. did you mean something like:

 
if (destination==japan_fare && age>12)

?

(note you need 2 '='s to test for equality).

Also, i see you are trying to read in 2 values and assign then to age and destination, but you have not prompted the user to do anything.
have a read of that link on file IO i pasted a few days ago.
Last edited on
tnx for the tip,, where do i need to put the braces mate? in the if and else if statement?? please show me an example.
Last edited on
something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
	if (destination==japan_fare)
	{
		discount=japan_fare*0.10;
		discounted_fare=japan_fare-discount;
	}
	else if (destination==japan_fare)
	{
		discount=japan_fare*0.05;
		discounted_fare=japan_fare-discount;
	}
	else if (destination==china_fare)
	{
		discount=china_fare*0.10;
		discounted_fare=china_fare-discount;
	}
	else if (destination==china_fare)
	{
		discount=china_fare*0.05;
		discounted_fare=china_fare-discount;
	}


essentially around the statements you want calling for that specific if or else.

If you use code tags in future posts it'll make things a lot clearer for anyone reading so you might get more help.
Last edited on
why is the output of the discount,discounted_fare wrong?
post your latest code please.
in code tags too :)
Topic archived. No new replies allowed.