Diary Farm sells organic brown eggs to local customers. They charge Rs 22.50 for a dozen for eggs, or rs 2.10 for individual effs that are not part of a dozen. Write a C++ Program a user for the number of eggs in the order and the displays the amount owned with a full explanation. For Example, typical output might be " You ordered 27 eggs. that's 2 dozens at rs 2.50 per dozen and 3 loose eggs at rs 2.10 each for a total of rs 51.30".
The program must iterate until zero is entered for the number of eggs.
Code:
#include<iostream>
using namespace std;
int main(void)
{
int n;
float price=0;
int r=0,q;
char ch;
do
{
cout<<"\nEnter Numbe of eggs OR zero (0) to exit :";
cin>>n;
if(n<0)
{
cout<<"Incorect Value";
}
else if(n==0)
{
exit(0);
}
else
{
q=n/12;
price+=q*22.50;
r=n%12;
price+=r*2.10;
}
cout<<"\nThat's "<<q <<" dozen at Rs 22.50 per dozen and "<<r<<" loose eggs at Rs.2.10 each\n"<<"For a total of "<<price;
cout<<" \nPress y to continue: ";
cin>>ch;
}while(ch=='Y' ||ch=='y');
}
output:

Comments
Post a Comment