How should I edit my C++ code below? It displays the incorrect math answer to the fare. //PASSENGER’S FARE #include using namespace std; int main(){ float distance_km, fare; int passenger, vehicle, vehicle_opt; cout << "Enter the distance in kilometers: "; cin >> distance_km; cout << "Choose the type of vehicle: " << "\n"; cout<<"1. Taxi"<<"\n"; cout<<"2. Jeepney"<<"\n"; cin >> vehicle; cout << "Choose the type of passenger: " << "\n"; cout<<"1. Regular"<<"\n"; cout<<"2. Student"<<"\n"; cout<<"3. Senior"<<"\n"; cout<<"4. Person with Disability"<<"\n"; cin >> passenger; switch(vehicle_opt) { case 1: fare = 40 + 15*(distance_km - 1); break; case 2: if(passenger==1){ fare = 7.50 + (1.15)*(distance_km - 4); }else{ fare = 6.00 + (0.92)*(distance_km - 4); } break; } cout<<"-------------------------------\n"; cout<< "Passenger's Fare: " <
How should I edit my C++ code below? It displays the incorrect math answer to the fare.
//PASSENGER’S FARE
#include <iostream>
using namespace std;
int main(){
float distance_km, fare;
int passenger, vehicle, vehicle_opt;
cout << "Enter the distance in kilometers: ";
cin >> distance_km;
cout << "Choose the type of vehicle: " << "\n";
cout<<"1. Taxi"<<"\n";
cout<<"2. Jeepney"<<"\n";
cin >> vehicle;
cout << "Choose the type of passenger: " << "\n";
cout<<"1. Regular"<<"\n";
cout<<"2. Student"<<"\n";
cout<<"3. Senior"<<"\n";
cout<<"4. Person with Disability"<<"\n";
cin >> passenger;
switch(vehicle_opt)
{
case 1:
fare = 40 + 15*(distance_km - 1);
break;
case 2:
if(passenger==1){
fare = 7.50 + (1.15)*(distance_km - 4);
}else{
fare = 6.00 + (0.92)*(distance_km - 4);
}
break;
}
cout<<"-------------------------------\n";
cout<< "Passenger's Fare: " <<fare;
return 0;
}


Step by step
Solved in 2 steps with 1 images









