A new shop named Healthy Fruits has opened in a town, suppose they have hired you as a software engineer to make a program for them to store fruits names with prices lists, as well as for them to keep track of their sales. The program should display the following Menu to users.
1. Insert/Store Fruits names and prices
2. Display the fruit’s list (Fruit names with Prices)
3. Buy Fruits
4. Display the Sales/Bills of customers who have bought fruits
#include <iostream>
#include <string>
using namespace std;
int main(){
int choice;
string names[100];
int prices[100]{};
int bought[100]{};
int i = 0;
do{
cout<<"1. Insert/Store Fruits names and prices\n";
cout<<"2. Display the fruit's list (Fruit names with Prices)\n";
cout<<"3. Buy Fruits\n";
cout<<"4. Display the Sales/Bills of customers who have bought fruits\n";
cin>>choice;
string s;
int p;
int total{};
switch(choice){
case 1: cout<<"Enter name: ";
cin>>names[i];
cout<<"Enter price: ";
cin>>prices[i];
i++;
break;
case 2: for(int j = 0; j < i; j++){
cout<<"Name: "<<names[j]<<"\n";
cout<<"Price: "<<prices[j]<<"\n\n";
}
break;
case 3: cout<<"Enter name: ";
cin>>s;
cout<<"Enter price: ";
cin>>p;
for(int j = 0; j < i; j++){
if(names[j] == s){
if(prices[j] <= p){
bought[j]++;
cout<<"Sold!\n";
}
else{
cout<<"Not enough money\n";
}
}
}
break;
case 4: for(int j = 0; j < i; j++){
if(bought[j]){
cout<<"Name: "<<names[j]<<"\n";
cout<<"Price: "<<prices[j]<<"\n";
cout<<"Quantity: "<<bought[j]<<"\n";
total += bought[j] * prices[j];
}
cout<<"Total: "<<total<<"\n";
}
break;
}
}while(choice <= 4 && choice > 0);
return 0;
}
Comments
Leave a comment