Having trouble with arrays, Need help w/ assignment!

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

32 Replies - 1647 Views - Last Post: 16 December 2012 - 09:00 PM Rate Topic: -----

#31 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,449
  • Joined: 09-June 09

Re: Having trouble with arrays, Need help w/ assignment!

Posted 16 December 2012 - 06:44 PM


while (chart[row_num][seat_num] == '*')
{
cout << "The position you picked is filled. Please enter another row number: ";
cin >> row_num;
}




This code will check the condtion and then ask for the user input, however you need to do the exact opposite. You need to ask for input, and then check the condition.

This can be done by asking for row_num input before your while loop, and also after the input is invalid
i.e.
cin>>row_num; //get input
while (chart[row_num][seat_num] == '*') //check condition
{
cout << "The position you picked is filled. Please enter another row number: ";
cin >> row_num; //keep getting input if it condition is false
}


The code above however seems a little repetitive, you can fix this by asking for input within the actually while loop condition.
while (cin >> row_num && chart[row_num][seat_num] == '*')
   cout << "The position you picked is filled. Please enter another row number: ";


This post has been edited by jjl: 16 December 2012 - 06:48 PM

Was This Post Helpful? 0
  • +
  • -

#32 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1276
  • View blog
  • Posts: 4,395
  • Joined: 19-February 09

Re: Having trouble with arrays, Need help w/ assignment!

Posted 16 December 2012 - 07:04 PM

What is the purpose of this for loop? Do you need it?

068	        for (r = 0; r < ROWS; r++)
069	        {



What is the purpose of this for loop? Do you need it?

073	        while (approve == 'N' || approve == 'n')
074	        {





I did a quick design and came up with

while pick seat
{
  get row and number

  if NOT row and number good
  {
    print error
  }
  else
  {
    display price
    get approval

    if approved
    {
      if(valid empty)
        update chart 
      else
        print error
    }
  }
  display chart
  ask pick another seat
}


Was This Post Helpful? 0
  • +
  • -

#33 CY5  Icon User is offline

  • D.I.C Regular

Reputation: 10
  • View blog
  • Posts: 315
  • Joined: 28-September 12

Re: Having trouble with arrays, Need help w/ assignment!

Posted 16 December 2012 - 09:00 PM

Your program works very well, and its good, but requires some modification there is no option to exit and once seat is given to someone should not be available for others
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3