if else and sending to columnar report.

I am new to programming and I am trying in my if else statement (if a bag is over 50lbs for there to be an added 25.00 dollar charge. I set the variable (BagCharge = 25) but I can't get it to ignore the 25.00 charge if the weight is less than 50. Either way it still prints the 25.00 to the report. I apologize it this isn't the clearest question. Thank you for your help.

cout << "How much does the first bag weigh?\n";
cin >> bag1Weight;
if( bag1Weight > 50)
{cout << "Over 50 lbs, overweight charge for bag 1 is $25.";
cout <<"How much does the second bag weigh?";}

else

{ cout << "The first bag is free\n";
cout << "How much does the second bag weigh?";}
cin >> bag2Weight;
if(bag2Weight > 50)
cout << "Over 50 lbs; overweight charge for bag 2 is $25.\n";



cout << "Passenger information:\n";
cout << "Passenger Name (Last, First: FFN) Cost\n";
cout << "=====================================================\n";



cout << Last_name <<", " << First_name << ": " << FrequentFlyerNumber << endl;
totalCost = Ticket +bag1Cost+bag2Cost;

cout << setprecision(2) << fixed;
cout << "TICKET: $" << setw(8) << Ticket << endl;
cout << " BAG1: $" << setw(8) << bag1Cost << endl;
cout << " BAG2 $" << setw(8) << bag2Cost << endl;
cout << " TOTAL $" << setw(8) << totalCost << endl;

How much does the second bag weigh?51
Over 50 lbs; overweight charge for bag 2 is $25.
Passenger information:
Passenger Name (Last, First: FFN) Cost
=====================================================
doe, John: 1234567
TICKET: $ 23.45
BAG1: $ 25.00
BAG2 $ 25.00
TOTAL $ 73.45
Please provide compileable code. Some of your errors come from outside this snippet.
Please put the code in code tags or the indentation which you (hopefully) are using is invisible.

I don't see a variable BagCharge anywhere in this code snippet. Nor do I see where bag1Cost and bag2Cost are set as 25. Presumably you did these before this snippet? Who knows?

if ( bag is overweight )
{
   state charge for overweight baggage;
   if not already done, set that bag cost to BagCharge;
}
else
{
   set that bag cost to 0;
}

Thank you for taking the time to reply. I appreciate your help. Here is the code in its entirety. I apologize for the lack of detail in the first post. I have literally just started programming and this is my first forum. Thanks again... I just couldn't figure out how to get the 25.00 added or not added in the columnar report.

//============================================================================
// Name :
// Author :
// Version :
// Copyright :
// Description :
//============================================================================

#include <iostream>
#include <string>
#include <iomanip>


using namespace std;

int main()
{

string First_name, Last_name, FrequentFlyerNumber;
double bag1Weight, bag2Weight,bag1Cost,bag2Cost, totalCost, Ticket ;

bag1Cost = 25;
bag2Cost = 25;





cout << "Please enter the passengers first name:\n";
getline(cin,First_name);
if(First_name.size() > 12 )
{cout << "Error\n";
cout << "FN: John" << endl;
}
else if (First_name.size() < 1 )
{cout << "Error\n";
cout << "FN: John" << endl;
}
else
cout << "FN: "<< First_name << endl ;

cout << "Please enter the passengers last name:\n";
getline(cin,Last_name);
if(Last_name.size() > 20 )
{cout << "Error\n";
cout << "LN: Doe\n";}
else if (Last_name.size()< 1 )
{cout << "Error\n";
cout << "LN: Doe\n";}
else
cout << "LN:" << Last_name << endl;


cout << "What is the frequent flyer number:\n";
getline(cin, FrequentFlyerNumber);
if(FrequentFlyerNumber.size() > 7)
{cout << "NA:\n";
cout << "What is the cost of the airline ticket?\n";
}
else if(FrequentFlyerNumber.size() < 7)
{cout << "NA:\n";
cout << "What is the cost of the airline ticket?\n";
}
else
cout << "What is the cost of the airline ticket?\n";
cin >> Ticket;



cout << "How much does the first bag weigh?\n";
cin >> bag1Weight;
if( bag1Weight > 50)
{cout << "Over 50 lbs, overweight charge for bag 1 is $25.";
cout <<"How much does the second bag weigh?";}

else

{ cout << "The first bag is free\n";
cout << "How much does the second bag weigh?";}
cin >> bag2Weight;
if(bag2Weight > 50)
cout << "Over 50 lbs; overweight charge for bag 2 is $25.\n";



cout << "Passenger information:\n";
cout << "Passenger Name (Last, First: FFN) Cost\n";
cout << "=====================================================\n";



cout << Last_name <<", " << First_name << ": " << FrequentFlyerNumber << endl;
totalCost = Ticket +bag1Cost+bag2Cost;

cout << setprecision(2) << fixed;
cout << "TICKET: $" << setw(8) << Ticket << endl;
cout << " BAG1: $" << setw(8) << bag1Cost << endl;
cout << " BAG2 $" << setw(8) << bag2Cost << endl;
cout << " TOTAL $" << setw(8) << totalCost << endl;








return 0;
}
Thank-you for posting the entire code. Now, go back and read @lastchance's post

First, he requested that you post your code inside code tags. If you don't know how, ask questions. But please don't just ignore requests. There are reasons we like code tags, and as you get more familiar with this site, you will want to see them, too.

So, go back to your previous post. Highlight the entire contents of your code file. Then click the Format button that looks like "<>". (Hopefully the indentation in your code did not get lost from when you originally posted.)

Also, @lastchance gave you logic for solving your problem. The pseudo-code (logic only--not compiliable C++ code) that he gave you at the end of his post will fix your problem. Read it and try to understand it. Then implement it into your code.
Topic archived. No new replies allowed.