I am making a simple program that asks for the number of miles a car gets when driving on one gallon of gas. Then it asks how many gallons are in the car's tank. I'm pretty sure I'm doing this right but when I run it, it doesn't output correctly or let me finish the inputs. This is inside an empty c++ project as well if that affects anything.
#include <iostream>
//Displays C++
//Created by Christopher Robinson on 1-29-2018
usingnamespace std;
int main()
{
double gallons = 0 ;
double cMiles = 0 ;
double hMiles = 0 ;
double maxHDrive = 0 ;
double maxCDrive = 0 ;
char vehicle;
cout << "What is the brand of your vehicle?" << endl;
cin >> vehicle;
cout << "What is maximum capacity, in gallons, of your gas tank?" << endl;
cin >> gallons;
cout << "How many city miles can you drive with one gallon of gas?" << endl;
cin >> cMiles;
cout << "How many highway miles can you drive with one gallon of gas?" << endl;
cin >> hMiles;
maxCDrive = gallons * cMiles ;
maxHDrive = gallons * hMiles ;
cout << "The maximum city mile you can drive in your "
<< vehicle << " is " << maxCDrive << " miles before you require a fill-up." << endl;
cout << "The maximum highway miles you can drive in your "
<< vehicle << " is " << maxHDrive << " miles before you require a fill-up." << endl;
system ("pause");
return 0;
}
{output display}
What is the brand of your vehicle?
ford
What is maximum capacity, in gallons, of your gas tank?
How many city miles can you drive with one gallon of gas?
How many highway miles can you drive with one gallon of gas?
The maximum city mile you can drive in your f is 0 miles before you require a fill-up.
The maximum highway miles you can drive in your f is 0 miles before you require a fill-up.
Press any key to continue . . .
I have a bunch of errors showing where << is on the final cout statements and at the initial cin the >> is showing as an error as well.... (red squiggles).
Add the header #include <string>
(although it will probably be invoked by iostream anyway).
It then produces the following output in c++ shell.
What is the brand of your vehicle?
Ford
What is maximum capacity, in gallons, of your gas tank?
10
How many city miles can you drive with one gallon of gas?
30
How many highway miles can you drive with one gallon of gas?
50
The maximum city mile you can drive in your Ford is 300 miles before you require a fill-up.
The maximum highway miles you can drive in your Ford is 500 miles before you require a fill-up.
If you insist on using Visual Studio then it might want precompiled header of its own but I know nothing about that.