i'm confused

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deltamami0999
    New Member
    • Feb 2008
    • 16

    i'm confused

    i'm having trouble understanding this problem...can someone explain to me what to do?

    Define a data structure named Car that stores two values: year and miles per gallon. Write a program that declares a variable of the Car type. Read in values for each field from stdin, then output the stored values to stdout.


    this is what i have so far:
    class Car
    {
    public:

    int year;
    int mpg;

    I dont know how to declare a variable of the car type....we're going by Y. Daniel Liang's Introduction to Programming with C++ book...
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Maybe:

    [code=cpp]
    Car myCar;
    [/code]

    Comment

    • deltamami0999
      New Member
      • Feb 2008
      • 16

      #3
      Originally posted by weaknessforcats
      Maybe:

      [code=cpp]
      Car myCar;
      [/code]

      i don't what to do after that....my code looks all messed up....

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Well, let's see what you have.

        Comment

        • deltamami0999
          New Member
          • Feb 2008
          • 16

          #5
          Originally posted by weaknessforcats
          Well, let's see what you have.
          #include <iostream>
          using namespace std;

          class Car
          {
          public:




          Car myCar;

          int main()
          {

          //Declare variables
          int year;
          int mpg;





          system("pause") ;
          return 0;
          }

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            First, the year and the mpg are inside the class rather than outside.

            I would write a class Car that shows this. How you do this is in your book.

            Then, post your class Car and we'll go from there.

            Do not worry about the other stuff until your class Car has been written.

            Comment

            Working...