I'm having trouble with a input data stream, the data file is a .txt file with names, amount of coffee ordered and type of coffee, see below. There are 5 total orders with a whitespace in between each order.
Draco Malfoy
13
Plain Coffee
Ron Weasley
28
Latte
etc...
I"m trying to have this data feed into my program, but once it inputs it just repeats the first entry, Draco Malfoy for 5 times and does not pick up other orders. See code below.
ifstream inputFile;
inputFile.open("Project_3data.txt");
if (inputFile.fail())
{cout << "Error opening file.\n";
}
for ( int count = 0; count <= orders; count++)
{
If you don't present complete code and you don't put it in code tags to make it readable it can be extremely difficult for people to assist. There is no way this would compile, so I'm surprised it produced any output at all.
However, here are some things that may be part of your problem.
if (users_order = 'Plain')
There are (at least) two things wrong here:
= is an assignment operator; == is the logical comparison for equality and is what you need here.
Single quotes ' go round a single character (char). You need double quotes " around a string.
The same is true of all the if statements in that block.
You are splitting up into two parts both names and orders. In the latter case this obviously wouldn't work because some of the orders - e.g. "Latte" have just a single word. For both name and order I would use getline rather than >> and use a single string to hold the name and a single string to hold the order. In fact, as long as you can guarantee the format of the input file I would use getline for all the input. You can stringstream any numerical values into their int or double variables.
for ( int count = 0; count <= orders; count++)
This will loop orders+1 times: is that what you intended? At a rough guess, as orders (=5?) is apparently known, you meant for ( int count = 0; count < orders; count++)