The second cout statement won't output

No description need really...

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
44
45
46
47
48
// Defines constructor, destructor, and range() function in-line.

#include <iostream>

// Declare the Vehicle class.
class Vehicle {
      // These are now private
      int passengers; // number of passengers
      int fuelcap; // fuel capacity in gallons
      int mpg; // fuel consumption in miles per gallon
      
      public:
        // This is a constructor for Vehiclce.
        Vehicle(int p, int f, int m) {
              passengers = p;
              fuelcap = f;
              mpg = m;
              }
        
        // Compute and return the range.
        int range() { return mpg*fuelcap; }
        
        // Accessor functions.
        int get_passengers() { return passengers; }
        int get_fuelcap() { return fuelcap; }
        int get_mpg() { return mpg; }
};

int main()
{
    // Pass values to Vehicle constructor.
    Vehicle minivan(7, 16, 21);
    Vehicle sportscar(2, 14, 12);
    
    int range1, range2;
    
    // Compute the ranges assuming a full tank of gas.
    range1 = minivan.range();
    range2 = sportscar.range();
    
    std::cout << "Minivan can carry " << minivan.get_passengers() << " with a range of "
              << range1 << "\n";
    std::cout << "Sportscar can carry " << sportscar.get_passengers() << " with a range of "
              << range2 << "\n"; // This doesn't output, nor do any othersI try to output aswell
    
    std::cin.get();
    return 0;
}      


Thank you.
Works fine for me.
Hmm Dev-C++ must have issues with classes or something. Or maybe its how mine is set up? VC++ displays it correctly.
I tested it with MinGW. Dev-C++'s version of MinGW is pretty old, though.

EDIT: Oh, I just remembered. I have had issues with MinGW sending output to the wrong streams at the wrong times for no apparent reason, by the way.
Last edited on
Ok, will bare that in mind in future exercises.
Topic archived. No new replies allowed.