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;
}