Answer to Question #198747 in C++ for June

Question #198747

The program accepts two inputs, namely: a train station number indicating where the passenger will board the train, a second train station number indicating where the passenger will get off from the train. Train stations are numbered consecutively from 1 to 100. The train fare is computed based on the number of stations that the passenger will pass through. Included in the counting are the stations where he/she boarded and the station where he/she got off. For example, if the passenger boarded at station 51 and got off at station 85, then the passengers passed through a total of 35 stations. A fixed fare of 30.00 Pesos should be paid by the passenger for the first 20 stations. An additional 1.25 Pesos is charged for every additional station. The program should output the the count or number of stations passed through by the passenger and the train fare.


1
Expert's answer
2021-05-26T06:25:05-0400
#include <iostream>
#include <vector>
using namespace std;


vector<double> calculate(int a, int b){
  vector<double> c;
  double count=b-a+1;
  c.push_back(count);  
  if (count<=20)
    c.push_back(30);  
  else
    c.push_back(30+(count-20)*1.25);
  return c;
}


int main()
{
    vector<double> v =calculate(4, 75);
    cout<<"Count station: " << v[0]<<endl;
    cout<<"Total price: " << v[1]<<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

Assignment Expert
27.05.21, 07:59

Dear June,

You're welcome. We are glad to be helpful. 

If you liked our service please press like-button beside answer field. Thank you!



June
27.05.21, 04:01

Thank you so much for the help

Leave a comment

LATEST TUTORIALS
New on Blog