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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment