C++ program to calculate total fuel consumption of a month with dummy data (with algorithm)



Here is the C++ code fuel consumption calculator for a month. It works on dummy data provided to it you can add your own data for exact calculations. You all should have in mind how it works exactly. Here is the algorithm.

  Steps

Developer side
1: Declare variables that are going to be used in program.
2: Calculate fuel for first 3 days of week by using following statement      day3=72*71.1;
3: There are 4 weeks in a month so multiply the result by 4
4: Calculate consumption for 4 Saturdays. 
5:Calculate consumption for other 3 days of week
6: There are 4 weeks in a month so multiply the result by 4
7:  Add up the results of above points 3, 4 and 6
8: Program end
Code:

#include<iostream>
using namespace std;
void main()
{      //Declaration of varibles
       float day3,sat,other3,finalfuel;
       //first three days
       cout<<"consumption of first 3 days of weeks="<<endl;
       day3=72*71.1;
       cout<<day3<<"galans"<<endl;
       cout<<"There are 4 weeks in a month so"<<endl;
       day3=day3*4;
       cout<<day3<<"gallans"<<endl;
       //saturdays
       cout<<"There are 4 saturdays in a month so consumption of gallans "<<endl;
       sat=96*21.6;
       cout<<sat<<"gallans"<<endl;
       //other days
       cout<<"consumption of other 3 days of weeks="<<endl;
       other3=72*52.1;
       cout<<other3<<"galans";
       cout<<"There are 4 weeks in a month so"<<endl;
       other3=other3*4;
       cout<<other3<<"gallans"<<endl;
       //finalfuel
       finalfuel=day3+sat+other3;
       cout<<"Total Fuel consumption of one month= "<<finalfuel<<" gallans"<<endl;
       system("pause");
}

Output:

Comments

Post a Comment