Answer to Question #27109 in Visual Basic for harvey masuluke

Question #27109
Poppy, who counts every cent to get the best value for her money, needs to buy washing powder. She went to the shop and wrote down the prices of the 500g, 750g, 1 kg packets of her favourite washing powder. She want to write a programme to determine which one of the packets is the best buy (most economical). Do the calculations and display which packet for all three packet.
1
Expert's answer
2013-03-27T11:16:14-0400
/*
Poppy, who counts every cent to get the best value forher money, needs to buy washing powder. She went to the shop and wrote down the
prices of the 500g, 750g, 1 kg packets of her favourite washing powder. She
want to write a programme to determine which one of the packets is the best buy
(most economical). Do the calculations and display which packet for all three
packet.
*/
#include<iostream>
using namespace std;
int main()
{
// weights ofpackets
double m[3] ={500.,750.,1000.};
// prices forone packet
double p[3];
// prices forone gram
double pg[3];
// minimalprice per gramm, and the number of packet
double pg_min;
int pg_ind;
int i;

for (i=0;i<3; i++)
{
cout<< "Enter the price for " << m[i] << "g
packet: ";
cin>> p[i];
pg[i] =p[i]/m[i];
cout<< "The price for 1 gramm is " << pg[i] << endl;
}
// find minimalelements
pg_min=pg[0];
pg_ind=0;
for(i=1;i<3;i++)
{
if(pg_min>pg[i])
{
pg_min=pg[i];
pg_ind=i;
cout<< "Change minimum to " << i << endl;
}
}
cout <<"It is most economical to by packet of " << m[pg_ind] <<
" gramms.
";
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS