// 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>
using namespace std;
int main()
{
int,age,dc1,dc2,china,japan;
double discount,discounted_fare;
dc1=china;
dc2=japan;
japan=3000;
china=2500;
cin>>age;
cin>>destination;
if (dc1)
else if (age>12)
discount=dc1*0.10;
else
discounted_fare=dc1-discount;
cout<<discounted_fare;
discount=dc1*0.05;
system ("pause");
return 0;
}
#include <iostream>
usingnamespace std;
int main()
{
int,age,dc1,dc2,china,japan;
double discount,discounted_fare;
dc1=china;
dc2=japan;
japan=3000;
china=2500;
cin>>age;
cin>>destination;
if (dc1)
elseif (age>12)
discount=dc1*0.10;
else
discounted_fare=dc1-discount;
cout<<discounted_fare;
discount=dc1*0.05;
system ("pause");
return 0;
}
You have an extra comma on line 5 after int
on line 12 you read into a value called destination which you never declared. From your description, destination should be a string..
Your logic after that needs to be fixed. You need to set the initial fare according to the value of the destination input by the user, which you haven't done. Then you need to write your conditional statements properly. I suggest you go look at the tutorial on conditionals if you don't understand how to use them.
Line 7 and 8: dc1 and dc2 are initialized to garbage values. Move the initialization of japan and china up.
Line 15: same problem because of line 7.
Line 17: discount is not initialized.
Line 19: discount initialized to garbage value because of line 7.
Say you declare a variable: int x;
If you try to use x without giving it a value first (initialization), the result is undefined. Usually the compiler just takes whatever value is in the memory. So variables need to be initialized before use.
You don't need dc1 and dc2. All you need is a single variable, let's call it fare, assigned to china or japan based on what the user inputs for destination.