In desperate need of help....

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  #include <iostream>


//Displays C++
//Created by Christopher Robinson on 1-29-2018

using namespace 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 . . .
Last edited on
string vehicle;
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).
The errors are at vehicle everytime before the word. Says it has an invalid operand when I do string vehicle;
Change
char vehicle;
to
string vehicle;

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.
I've commented out vehicle and the program works perfectly. I'm trying to find out why that one statement throws everything off.
wow Visual Studio. -.- yep that fixed it alright. Thank you for your help lastchance.
Have you included the
#include <string>
as in my last post?

It's quite hard to just comment out vehicle here: it's used in several different places.
Registered users can post here. Sign in or register to post.