I need a loop for this, but i don't know how to put it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string prod;
double price, pos, can;
string name;
ifstream infile("productos1.txt");
cout<<"Producto: ";
cin>>name;
while (infile >> prod >> price)
{
if (name == prod)
cout <<"Precio: "<<price <<endl;
//i think here's where i've to put it.
}
cout<<"Cantidad: ";
cin>>can;
cout<<"Precio: "<<can*price;
infile.close();
}
|
Last edited on
A little more detail would be nice exactly what is to be looped. Does your current loop work, or is that the one you are having issues with?
Probably what I would do if you want to loop through the input of a file...
1 2 3 4 5 6 7
|
do
{
infile >> prod >> price;
//do your loop stuff now
} while (!infile.eof());
|
This way you loop through the program and stop when it hits the end of the file.
Last edited on
Okay, so first:
I put the name of the product, so if name == prod (which is on the txt)
should print price and quantity, and the final price.
In the end, there should be the option for the client to buy an other product. And go to the name of the product.
(I'm sorry if my english is very bad)