I am pulling a list of 3 items with a list price from a text file, I ask for the percentage off and calculate it against the list price then I update to file with revised price. The program compiles correctly, but it never displays the info in the console after I input the percent and hit enter. Data does flash onscreen and the text file gets created but the numbers are not correct. I tried using setprecision but it does not go two decimal places to the left as instructed.
an exampe of the data on file is like
goods 22.67
goods 24.00
Any knowledge would be appreciated.
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
double percent, appleP, coffeeP, teaP, coffeeN, appleN, teaN;
char Apples, coffee, tea;
// Open file that has the list prices
ifstream inputFile;
inputFile.open("productlistIn.txt");
//Close file with new price
ofstream outputFile;
outputFile.open("updatedproductlistIn.txt");
//Read list prices from file
//store them in the variables.
inputFile >> appleP;
inputFile >> teaP;
inputFile >> coffeeP;
//Get percentage from user.
cout << "Please enter the amount to increase the prioe" << endl;
cin >>percent;
cin.ignore( );
//Calculation for percentage increase
coffeeN = coffeeP * percent + coffeeP;
appleN = appleP * percent + appleP;
teaN = teaP * percent + teaP;
//Display the list price and new price
cout << "Apples "<< appleP << "new price "<< setprecision(2) <<fixed << appleN << endl;
cout << "coffee "<< coffeeP << "new price"<< setprecision(2) <<fixed << coffeeN << endl;
cout << "tea "<< teaP << "new price"<< setprecision(2) <<fixed << fixed <<teaN << endl;
//Write updated price to file.
outputFile << "Apples " << appleP << "new price "<< appleN << endl;
outputFile << "coffee "<< coffeeP << "new price"<< coffeeN << endl;
outputFile << "tea " << teaP << "new price" << teaN << endl;
// Close the file
outputFile.close();
cout << "Done.\n";
return 0;