View Single Post
Old 09-29-2005, 04:17 AM   #7 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Think about normal loops ie:
Code:
#include <iostream>

int main()
{
  unsigned int no_floors=0, no_rooms=0, no_op_rooms=0, temp=0;
  while(no_floors < 1)
  {
    std::cout << "Enter number of floors in building: ";
    std::cin >> no_floors;
    if(no_floors < 1)
       std::cout << "Error please enter 1 (ONE) or more floors" << std::endl;
  }
  for(int i=1; i <= no_floors; ++i)
  {
    if(i == 13)
      continue; /* skip 13th floor */
    /* bad programming style to use gotos
     * but if we know what we're doing.... 
     */
    start_over:
    std::cout << "Enter number of rooms on " << i << ". floor: ";
    std::cin >> temp;
    if(temp < 10)
    {
      std::cout << "Error you should give 10 or more rooms pr. floor" << std::endl;
      goto start_over;
    }
    no_rooms += temp;
    std::cout << "Enter number of occupied rooms on " << i << ". floor: ";
    std::cin >> temp;
    /* figuring out a way to check for more occupied rooms
     * than the floor has, is left as a user implementation 
     */
    no_op_rooms += temp;
  }
  std::cout << "The calculation is the users implementation" << std::endl;
  return 0;
}
This is just written directly into the composer here, and has not been tested/compiled/anything, if it will work, only god knows.. An even he might be wrong.

If you were to create a combination where it should portrait the number of rooms and occupied rooms pr. floors, then you should use the std::vector type for your no_rooms and no_op_rooms, where every instance in those vectors represents the floors.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001

Last edited by redhead; 09-29-2005 at 04:55 AM.
redhead is offline   Reply With Quote