7. Program that uses three arrays Mango, Orange and Banana to store the numbers of fruits purchased by customer. The program finally displays the total bill of each customer according to the prices.
Chapter 7:
Arrays
Programming Exercise
Problem # 7:
Write a program that uses three arrays Mango, Orange and Banana to store the numbers of fruits purchased bu customer. The program inputs the number of mangoes, oranges and bananas to be purchased by customer and stores them in corresponding arrays. The program finally displays the total bill of each customer according to the following prices:
Rs. 20 per mango
Rs. 10 per orange
Rs. 5 per banana
The output should appear as follows:
------------------------------------------------------------------------------------
Customer No. Mangoes Oranges Bananas Total Bill
------------------------------------------------------------------------------------
1 5 10 12 Rs. 260
Solution:
#include<iostream>
#include<conio.h>
using namespace std;
int main ()
{
int a, b, c, d;
cout<<"Enter the number of customers:";
cin>>a;
int mangoes[a], oranges[a], bananas[a], bill[a];
for(b=0;b<a;b++)
{
bill[b]=0;
cout<<"Customer "<<b+1<<" :"<<endl;
cout<<"Enter the number of Mangoes:";
cin>>mangoes[b];
bill[b]+=mangoes[b]*20;
cout<<"Enter the number of Oranges:";
cin>>oranges[b];
bill[b]+=oranges[b]*10;
cout<<"Enter the number of Bananas:";
cin>>bananas[b];
bill[b]+=bananas[b]*5;
}
cout<<"\n-------------------------------------------------------------------";
cout<<"\nCustomer No.\tMangoes\tOranges\tBananas\tTotal Bill";
cout<<"\n-------------------------------------------------------------------\n";
for(c=0;c<a;c++)
cout<<c+1<<"\t\t"<<mangoes[c]<<"\t"<<oranges[c]<<"\t"<<bananas[c]<<"\t"<<bill[c]<<endl;
}
#include<conio.h>
using namespace std;
int main ()
{
int a, b, c, d;
cout<<"Enter the number of customers:";
cin>>a;
int mangoes[a], oranges[a], bananas[a], bill[a];
for(b=0;b<a;b++)
{
bill[b]=0;
cout<<"Customer "<<b+1<<" :"<<endl;
cout<<"Enter the number of Mangoes:";
cin>>mangoes[b];
bill[b]+=mangoes[b]*20;
cout<<"Enter the number of Oranges:";
cin>>oranges[b];
bill[b]+=oranges[b]*10;
cout<<"Enter the number of Bananas:";
cin>>bananas[b];
bill[b]+=bananas[b]*5;
}
cout<<"\n-------------------------------------------------------------------";
cout<<"\nCustomer No.\tMangoes\tOranges\tBananas\tTotal Bill";
cout<<"\n-------------------------------------------------------------------\n";
for(c=0;c<a;c++)
cout<<c+1<<"\t\t"<<mangoes[c]<<"\t"<<oranges[c]<<"\t"<<bananas[c]<<"\t"<<bill[c]<<endl;
}
Output:
Let me know in the comment section if you have any question.
Previous Post:
6. Program that inputs marks of ten students. The program displays the number of students in each grade.
thanks good work keep it up ................
ReplyDeletenice
ReplyDelete