You are on page 1of 2

/*

Isaac Bernal
9/8/2022
Programming Fundamentals 3
Professor Lara
In this program, I am making use of the pointers through functions in this Mileage Calculator
*/

#include <iostream>
#include <cmath>//using division
#include <string>//user's info
using namespace std;

//------Prototype-----------
void input(string *, int *, float *, float *);//to gather users info with pointers
float cal(float *,float *); //calculating the mileage
void display(int *, string *, float *);

int main()
{
float gallon;
float *galPtr = &gallon;//address of variable assigned to pointer

float miles;
float *milPtr = &miles;//address of variable assigned to pointer

float mPg;
float *mpgPtr= &mPg;//address of variable assigned to pointer

string carMakeModel;
string *carInfoPtr = &carMakeModel;//address of string variable assigned to pointer
int carYear;
int *yearPtr = &carYear;

cout << "\t-_-Welcome to Vehicle Fuel Economy-_-\n\n";

//----Call to Function----
input(carInfoPtr, yearPtr, galPtr, milPtr);

mPg = cal(galPtr, milPtr);

display(yearPtr, carInfoPtr, mpgPtr);


return 0;
}

//-------Function Definition-------

//Received: Car's info and year, gas tank and miles


//Return: Nothing
void input(string *info, int *year, float *gas, float *mil)
{
cout << "What Make and Model of the vehicle:\n";
getline(cin, *info);
cout << "What Year is the vehicle:\n";
cin >> *year;
cout << "How many gallons of gas does the vehicle carry:\n";
cin >> *gas;
cout << "How many miles can the vehicle drive from a full tank:\n";
cin >> *mil;
}

//Received: Gallon and Miles


//Return: the mpg
float cal(float *gGal, float *gMiles)
{
return (*gMiles/ *gGal);
}

//Received: Car's info/gas and MPG


//Return: Nothing
void display(int *year, string *cInfo, float *mpg)
{
cout << "Your " << *year << ' ' << *cInfo << " fuel economy is: " << *mpg << " mpg.";
}

You might also like