Program skipping to the end!!

closed account (ohf3T05o)
I've been trying to figure this out forever. I always have trouble with if/esle if statements. The program I'm writing is simple.. all it does is calculate your gas price. When it runs, It's skipping to the end of the program and not doing the "cout" commands I asked.

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

#include <iostream>
#include <string>
using namespace std;
int main()
{
 
// Variables
     float miles_travelled, price;
     char a; 
  
 
// Select Car
    cout << "How many miles have you travelled \n";
    cin >> miles_travelled;
    cout << "What kind of car do you have: \n";
    cout << "Enter == 1 for Economy == OR == 2 for Gas guzzler == : \n";        
    cin >> a; 

// Economy car
    if (a == 1)
    { 
      price = (.25*miles_travelled);    
      cout << "You have an Economy Car" << endl;
      cout << "Total price is: " << price << endl;
    }

// Gas guzzler
   else if (a == 2)
   {
     price = (.35*miles_travelled);
     cout << "You have a Gas Guzzler" << endl;
     cout << "Total price is: " << price << endl;
   }
  
   else
     cout << "Invalid Type" << endl;
     return 0;

} //main
Attention: a is char so use a == '1' and a == '2' !
Last edited on
closed account (ohf3T05o)
Thanks condor. I didn't realize I was leaving out the single quotes.
Topic archived. No new replies allowed.