#include <iostream>
#include <fstream>
#include <string>
double total_price(int order);
int main()
{
usingnamespace std;
string menu[8];
int order, i=0;
char next, Y, y, N, n;
double total;
ifstream in_stream;
ofstream out_stream;
in_stream.open("menu.txt");
out_stream.open("order_lest.dat");
cout<<"Welcome to e-Chocolate! where you can find all the chocolate you can dream of!\n"
<<"please enter your choices, knowing that the chocolate is (2.00$) each."
<<"your first choice:";
for (i=0; i<8; i++)
{
order=menu[i];
cout<<i+1<<menu[i]<<"-"<<endl;
}
out_stream<<menu;
in_stream>>order;
total=total_price(order);
cout<<"Do you want anything else?(Y-N)\n";
cin>>next;
if (next==Y||next==y)
{
cout<<"please enter your choice:";
cin>>order;
if (next==N||next==n)
cout<<"your total is:"<<total<<"\t";
}
double total_price(int order)
{
double total;
total=order++;
return total;
}
in_stream.close();
out_stream.close();
return 0;
}
There is quite a bit wrong with this program, and that's without me trying to compile it.
-For starters lines 19 and 20 do not designate an open mode for menu.txt or order_lest.dat respectfully. I do not know if this will stop it from compiling but it is probably bad practice.
-In line 24 you appear to want to prompt the user for input but do not state in what format to input the choice nor do you have an input of anykind until Line 39. Also add a whitespace after the ':' on Line 24, trust me it will make the input look much better when you fix this.
-Line 29 To read the contents of the menu.txt file into the menu[] array replace "order=menu[i];" with "menu[i] >> in_stream;" without the quotes of course. If you are trying to do something else please inclued comments or some way to clarify.
- Line 33 will either need to be included in the for loop or have a for loop of it's own in order to write the menu array to order_lest.dat; and it will need to know what part of the menu array you are writing to out_stream.
- Line 34 you are just pulling the next input from in_stream and assigning it to the order integer, I am assuming based on Line 29 and the fact that menu is a string array that this will not work no matter how you try to do it because menu.txt contains text (I assume) which will not be assigned to an integer.
There is more but I would suggest rereading the chapter that you are on before going further.
Also you should try to keep your indentation consistent, this benefits your debugging process and people on the forum trying to help you.
if ( next==Y ...
There's a couple things you can do with this, namely because you have declared the char's y Y n Y
I assume you should probably initialize them if your going to use them in this way. eg.
char y='y', Y='Y', n='n', N='N' ;
this way your conditional will work, otherwise you can change the conditional to
if ( next == 'y' || next == 'Y' )
char y; is a variable it does not contain the value character 'y'.
it's the same as saying: int y;
what is y? it's not a character it's a number.
y = 666; // now is equal to 666.
using single letters for your variable names can become very confusing it's best to use words that make sense for example:
char yes='y', no='n';
then in the conditional if:
if ( next == yes || next == no ) // or something like this. it makes more sense...