Question: I need to be able to put in multiple records but when I try to put in more than one the initial cin statement for product name is ignored. I'm not sure what I'm doing wrong, a photo of what happens when I run the program is included. #include #include
Question: I need to be able to put in multiple records but when I try to put in more than one the initial cin statement for product name is ignored. I'm not sure what I'm doing wrong, a photo of what happens when I run the program is included.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{
ofstream w;
int c=1;
string filename;
cout << "File Name: ";
getline(cin, filename);
w.open(filename.c_str());
while(c==1){
string product_name;
cout << "Product name: ";
getline(cin, product_name,'\n');
w << product_name << endl;
double wppi; //wholesale price per item
cout << "Wholesale price: ";
cin >> wppi;
w << "Wholesale Price: " << wppi << " ";
int quanity;
cout << "Quanity: ";
cin >> quanity;
w << "Quanity: " << quanity << " ";
double total_price_paid;
total_price_paid = wppi * quanity;
double markup;
cout << "What is the markup? ";
cin >> markup;
double retail_price;
double anticipated_profit;
retail_price = wppi + markup;
anticipated_profit = total_price_paid - wppi;
w << "Retail Price: " << retail_price << " " << "Anticipated Profit: " << anticipated_profit << endl;
cout << "Do you want to process another record? Type 1 for Yes or 2 for No." <<endl;
cin >> c;
}
return 0;
}
Step by step
Solved in 4 steps with 2 images