62 556
Assignments Done
98,8%
Successfully Done
In June 2018

Answer to Question #12992 in C++ for madhurya

Question #12992
to calculate the petrol cost with any values using c++
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions