Answer to Question #12992 in C++ for madhurya

Question #12992
to calculate the petrol cost with any values using c++
1
Expert's answer
2012-08-10T09:38:08-0400
#include <iostream>
using namespace std;
int main()
{
//
initializing the variables:
int productID = 0;
const float priceList [] =
{0.85f, 1.10f, 1.35f};
float amount;
float total = 0.0f;

// getting
the data from user:
while (productID < 1 || productID > 3)
{
cout
<< "Please enter the petrol type ID (1, 2, 3): " << endl;
cin
>> productID;
}
cout << "Please enter the amount of petrol
needed: " << endl;
cin >> amount;

// calculating the
petrol cost:
total += amount * priceList [productID - 1];

//
output:
cout << "Total: " << amount << "lb x $" <<
priceList [productID - 1]
<< " = $" << total <<
endl;
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
APPROVED BY CLIENTS