Hi guys, I am kind of new to programming in C++ and I am currently working on a program that runs a an input file given to us by the professor. I set up an if-else statement that is supposed to display an error message if the program does not run smoothly and for the life of me I cannot figure out why the file is not running. Than you for taking the time to read this haha and if anyone is able to help it would be greatly appreciated
#include
#include
#include
#include
using namespace std;
class order_record
{
public:
string pname;
string cname;
double plant_cost;
double quantity;
double purchase_tax;
double net_cost;
double discount;
double total_cost;
};
void input(ifstream&, order_record&);
void output(const order_record&);
void process(order_record&);
/
void input(ifstream& in, order_record& plant_record) // example using the call by reference mechanism in C++ -- call record is passed by reference --note & operator
{
in >> plant_record.pname;
in >> plant_record.cname;
in >> plant_record.plant_cost;
in >> plant_record.quantity;
//add more code to read the rest of the fields (county name, plant cost, quantity) into the
//order record, plant_record.
}
void output(const order_record& plant_record)
{
//Use thee following statement to help you format you our output. These statements are called the magic formula.
cout.setf(ios::showpoint);
cout.precision(2);
cout.setf(ios::fixed);
cout << plant_record.pname << "\t";
cout << plant_record.cname << "\t";
cout << plant_record.plant_cost << "\t";
cout << plant_record.quantity << "\t";
cout << plant_record.net_cost << "\t";
cout << plant_record.purchase_tax << "\t";
cout << plant_record.discount << "\t";
cout << plant_record.total_cost<< "\t";
}
void process(order_record & plant_record)
{
plant_record.net_cost = plant_record.quantity * plant_record.plant_cost;
plant_record.total_cost = plant_record.net_cost + plant_record.purchase_tax - plant_record.discount;
if( plant_record.quantity <=0 )
plant_record.discount = 0;
else if(plant_record.quantity >= 1 && plant_record.quantity <=5 )
plant_record.discount = .01 * plant_record.net_cost;
else if(plant_record.quantity >= 6 && plant_record.quantity <=11 )
plant_record.discount = .03 * plant_record.net_cost;
else if(plant_record.quantity >= 12 && plant_record.quantity <=20)
plant_record.discount = .05 * plant_record.net_cost;
else if(plant_record.quantity >= 21 && plant_record.quantity <=50)
plant_record.discount = .08 * plant_record.net_cost;
else
plant_record.discount = .12 * plant_record.net_cost;
if(plant_record.cname == "dade" || plant_record.cname == "Dade")
plant_record.purchase_tax = .065 * plant_record.net_cost;
else if(plant_record.cname == "broward" || plant_record.cname == "Broward")
plant_record.purchase_tax = .06 * plant_record.net_cost;
else if(plant_record.cname == "palm" || plant_record.cname == "Palm")
plant_record.purchase_tax = .07 * plant_record.net_cost;
else
cout <<"Please enter the correct infromation";
}
int main()
{
order_record purchase_record;
string pname, cname;
double cost;
int quantity;
ifstream in; //declaring an input file stream
in.open("nursery_stock.txt"); //opening the input file stream
if (in.fail())
{
cout << "Input file did not open correctly" << endl;
}
else
{ //the following while loop processes one order record at a time
while (!in.eof())
{
input(in, purchase_record);
process(purchase_record);
output(purchase_record);
}
}
in.close(); //always close opened files.
return 0;
}