I have completed part 1 and part 2, I just need Part 3 (details below)I have attached the code and write-up along withPart 1: Write, Run, and Test the ApplicationUse the code in the Assessment 1 Part

Variables, Expressions, and Data Types 5

Variables, Expressions, and Data Types

Tapas Das

Capella University

Brad Berkland

Given Program

#include <iostream>

using namespace std;

int main()

{

int miles;

int gallons;

float mpg;

cout << "Enter miles: ";

cin >> miles;

cout << "Enter gallons: ";

cin >> gallons;

mpg = miles / gallons;

cout << "Miles per gallon: " << mpg;

return 0;

}

Modified Program

/* About the Milage Calculator program

This C++ program calculates miles driven

per gallon by a vehicle.

The user nneds to input total Miles driven by the vehicle

& the total no. of gallons consumed by the vehicle */

#include <iostream>

using namespace std;

int main()

{

float miles; // Variable miles : Total Miles driven

float gallons; // Variable gallons : Total no. of gallons consumed by vehicle

float mpg; // Variable gallons : Total no. of gallons consumed by vehicle

cout << "Enter miles: "; // Program prompts for total miles driven

cin >> miles; // User input for total miles

cout << "Enter gallons: "; // Program prompts for total gallons of fuel consumed

cin >> gallons; // User input for total gallons of fuel consumed

mpg = miles / gallons; // Program calculates MPG by dividing miles by gallon

cout << "Miles per gallon: " << mpg; // Program displays the MPG

return 0;

}

Part 3: Describe the Application

  • Define the variables in an application.

  • int miles;

  • int gallons;

  • float mpg;

The program got three variables, (1) miles (2) gallons and (3) mpg

Miles : total miles driven by the vehicle

Gallons: Total Gallons consumed to travel

MPG: Miles travelled per Gallon


  • Define the expressions in an application.

Expressions are methods of computation

mpg = miles / gallons;

in this program to calculate Miles per Gallon, we divide total miles by total gallons


  • Explain the data types in an application.

These data types are built-in or predefined data types and can be used directly by the user to declare variables. example: int, char , float, bool etc


Int holding whole numbers

Double used to define numeric variables holding numbers with decimal points

Float is used to hold real numbers with decimal point


  • Discuss the cause of the inaccuracy in the original code and the approach used to fix this problem.

Since we were using variable type as integer, it can hold only whole numbers

By using float as the variable type the problem is resolved

The functions very frequently used in C++ like cout, cin, string, vector, map, etc are built into C++ library namespace

  • Output of the Program

I have completed part 1 and part 2, I just need Part 3 (details below)I have attached the code and write-up along withPart 1: Write, Run, and Test the ApplicationUse the code in the Assessment 1 Part 1