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];
Comments
Leave a comment