i am trying to output the result in the output file and output to the screen. I could output to the file but I can not output to the screen what can I do ? what do I need to change or add?
thanks
this is the data
storeA 105
storeB 120
storeC 100
storeD 105
storeE 108
storeF 100
storeG 115
and this are the instruction.
A consumer research organization has a data file containing the names of stores and the price that each charges for a particular computer monitor. Write a program to determine the lowest price charged for that monitor and then print two lists.
list one. The names of all stores charging the lowest price.
list two. The names and prices for all stores whose price does not exceed the lowest price by more than 10%
I tried to debug it, but I couldn't do it,
would you please, help me I don't know what it's wrong !!!
thank you
#include <iostream>
#include <string>
#include <cassert>
#include <fstream>
using namespace std;
const int Max_numstores = 10;
int main ()
{
string names[Max_numstores]; // variables declarations
double prices [Max_numstores];
double lowestprice;
int numstores;
ifstream filein; // file stream declarations
ofstream fileoutLp;
ofstream fileoutLp10;
filein.open ("stores.txt"); //open a file for imput
fileoutLp.open ("lp.txt"); // open file for output
fileoutLp10.open ("lp10.txt");
lowestprice = 99999.0; //initialization
numstores = 0;
// find the lowest price
// input from input file
while (filein >> ws && !filein.eof())
{
filein >> names[numstores] >> prices[numstores];
if (prices[numstores] < lowestprice)
lowestprice = prices[numstores];
numstores++;
}
// find stores that not exceed the lowest price by 10%
// output from output files
for (int i=0; i<numstores; i++)
{
if (prices[i] == lowestprice)
fileoutLp << names[i] << endl;
else if (prices[i] <= lowestprice * 1.1)
fileoutLp10 << names[i] << endl;
}
filein.close();// closing files
fileoutLp.close();
fileoutLp10.close();
return 0;
}


Sign In
Create Account

Back to top









