Sample run of the program:
Welcome …
Please type in your budget: 120
Menu
Select an item from the above menu: 2
How many of this item you want?: 2
Please confirm [Y : yes, N : no] ?: Y
Total cost for this item = 50.000, Budget remaining = 70.000
The menu again
Select an item from the above menu: 8
Wrong choice !!
The menu again
Select an item from the above menu: 3
How many of this item you want?: 3
Please confirm [Y : yes, N : no] ?: Y
Total cost for this item = 10.200, Budget remaining = 59.800
The menu again
Select an item from the above menu: 6
How many of this item you want?: 5
Total cost for this item =151.800
Sorry, You don’t have enough money !!
The menu again
Select an item from the above menu: 7
Thanks ..
------The part below should be printed to both, screen and output file output.txt---------
Number of items bought = 2
Total cost = 60.200
Remaining budget = 59.800


File: input.txt
12.500
25.000
3.400
10.000
2.500
25.300

1 Dishdasha 12.500
2 Abaya 25.000
3 Hijab 3.400
4 Musarr 10.000
5 Shoes 2.500
6 Dress 25.300
7 Exit

#include <iostream.h>

#include <iomanip.h>

#include <fstream.h>

main()
{

int y;
int x=1;
double j;
int c;
int N;
double total;
double remain;
cout<<"Welcome...\n";
cout<<"Please type in your budget: ";
cin>>y;

ifstream myfile;

myfile.open ("input.txt");

if(myfile.fail())
cout <<"could not open file\n";
while(x<7)
{
cout<<"1 Dishdasha 12.500\n"
<<"2 Abaya 25.000\n"
<<"3 Hijab 3.400\n"
<<"4 Musarr 10.000\n"
<<"5 Shoes 2.500\n"
<<"6 Dress 25.300\n"
<<"7 Exit"<<endl;

cout<<"select an item from the above menu: "<<endl;
cin>>x;
if (x=1)
j=12.500;
else if(x=2)
j=25.000;
else if(x=3)
j=3.400;
else if(x=4)
j=10.000;
else if(x=5)
j=2.500;
else if(x=6)
j=25.300;
else if (x>7)
cout<<"wrong choice"<<endl;


cout<<"Please confirm [Y:yes,N:no]?:";
cin>>c;
if (c=N)

break;

}


total=j*x;
remain=y-total;
cout<<"total cost for this item = "<<total<<",Budget reminig= "<<remain<<endl;

cout<<"ssss"<<x<<endl;

return 0;
}

Please use code tags when posting code. That involves putting the word code in square brackets before the first line of code and the snippet /code in square brackets after the last line of code. That will preserve your indentation and make it much easier for us to read.

Just posting requirements and code isn't enough. You also need to indicate what isn't working the way you want. Does the code not compile? Do you not understand error messages? Is there a run time error and if so of what type? Do you not understand how to use a switch statement or some other programming tool? Etc.

In quickly looking at your code I notice that you apparently think the a single = means equals. For better or worse, in C/C++ a single = means assign the value on the right hand side of the = to tho the variable on the left hand side of the = sign. If you want to indicate equals rather than assignment, you must use two = signs in sequence. So = means assignment and == means equals. Therefore, if you want to compare variables in a conditional such as a while() or an if() or whatever, you want to use the == and not the = sign.

thank you lerner for your advice

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.