i have a .txt file that im reading from that looks like this:::
H 80 6 S
M 15 0 D
E 30 2 S
M 23 7 D
S 54 3 S
O 72 2 D
H 85 0 S
O 54 9 S
disregarding the first column....
the second and third column represent an amount of people (Adults, Children)
(NOTE: adults and children have different multiply values)
adult S value = 5.00
adult D value = 7.00
children S value = 2.00
children D value = 4.00
how do i tell the program to multiply by the "S" or "D" values for the correct column ?
im very... very new to C++, any help to get me on my way would help
Files are read line by line.
You code will be like this:
while you can read things from the file,
cin >> something
cin >> adults
cin >> children
cin >> SorD
if SorD == "S" then adults *= 5; children *= 2;
else adults *= 7; children *= 4;
do stuff ...
i get that part, the whole line by line thing....
...i guess where i get confused at is when you have to use functions outside the main....
.. i draw a complete blank and get all confused :/
Well, that's not right. In my example I wrote "cin", where I meant "infile". Sorry about that. Apart from that your problem is that you never call any functions. How do you expect them to process data if you never tell them to do so? Also, you use variables without declaring them. There are other problems, but lets fix there first.
When writing code it is a good idea to start with a subset of it. That way you can test it more often and it is easier to fix a shorter program.
For now, write a program with two functions. main() and getroom_price().
main should open and read from a file. At the end of each line call getroom_price and print it's results. Things to fix in main: roomselection, numchildren, numadults and mealtype are all undeclared. Declare them and make sure you give them correct types. Also, why is price a string?
getroom_preice is almost good. Again, why did you decide to make price a string?
Another thing is that you're overusing passing by reference. This isn't really bad, but it might be more comfortable to return values. Do you know how to do that? Try changing getroom_price to "double getroom_price(string& str)".