Creating a variable

This is a discussion on Creating a variable within the C++ Programming forums, part of the General Programming Boards category; I am looking for lines of code that would create a variable of the Flight structure named myFlight and assign ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    6

    Creating a variable

    I am looking for lines of code that would create a variable of the Flight structure named myFlight and assign 1274 as the flightNumber and 675 as the flightMiles?

    This is what I think:

    Code:
    Flight myFlight = { 1274, 675 };

    Any thoughts from anyone on my answer.

    Thanks

    Jamina

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    How about:

    Flight myFlight(1274, 675);

    or

    Flight myFlight=Flight(1274, 675);


    Those are a lot more intuitive (IMO) and are done simply by having a constructor that takes those two parameters.

  3. #3
    Pursuing knowledge confuted's Avatar
    Join Date
    Jun 2002
    Posts
    1,916
    or...
    Code:
    Flight myFlight;
    myFlight.flightNumber = 1274;
    myFlight.flightMiles = 675;
    Away.

  4. #4
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Or

    Flight myFlight;
    myFlight.SetFlightNumber(1274);
    myFlight.SetFlightMiles(675);



  5. #5
    plzduntlakliekthiskthx
    Join Date
    Oct 2002
    Posts
    138
    My post on your other thread:
    Yeah, remember to create an instance of the struct by doing:
    Code:
    Flight instance_of_flight;
    instance_of_flight.flightNumber=635;
    instance_of_flight.flightMiles=22;
    but of course use a better name for yours

  6. #6
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Yeah, but classes should be used to hide the important data.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C variable
    By webstarsandeep in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 01:26 AM
  2. Static Local Variable vs. Global Variable
    By arpsmack in forum C Programming
    Replies: 7
    Last Post: 08-21-2008, 03:35 AM
  3. Problem with a char variable set as a letter
    By 7smurfs in forum C++ Programming
    Replies: 6
    Last Post: 12-10-2004, 12:25 PM
  4. Static global variable acting as global variable?
    By Visu in forum C Programming
    Replies: 2
    Last Post: 07-20-2004, 08:46 AM
  5. creating a filename based on a variable
    By Waldo2k2 in forum C++ Programming
    Replies: 3
    Last Post: 05-22-2002, 05:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21