C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 25th, 2005, 01:43 PM
Rift Rift is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Location: Arizona
Posts: 5 Rift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 48 sec
Reputation Power: 0
Send a message via AIM to Rift Send a message via MSN to Rift Send a message via Yahoo to Rift
Compilation error and question in regards to iteration

Yeah, I know it's common for a newbie to start a "typical newbie thread." However, I'm not your typical newbie (well, sorta, but you'll get my drift later on). Err, okay!

Anyway, I am fairly new (read: BRAND new) to programming in C source. I've actually had a lot of fun with the semester so far. My favorite aspect of programming is the fact that you can pretty much mold any code, whether it be loops, functions, string literals, arrays, etc., into cooperative structural form. Basically what I'm saying is, you can do ANYTHING with programming, and though I'm still a "hatchling" (since I just now started in C), I think it's fun.

Anyway, I'm glad I found this site. I've been searching for help for a few days now, over some (hopefully) simple stuff. Maybe it's stuff I overlooked, I'm not sure. Hopefully someone will be able to help me briefly; I promise not to be too much of a burden!

My instructions were to create a program that did the following: (1) calculate hotel occupancy as a percentage, (2) how many floors the hotel has, (3) how many guest rooms on each floor, (4) how many OCCUPIED guest rooms on each floor, and (5) it is not allowed to accept a number of floors entry of less than 1 or less than 10 rooms on any floor. Along with this is something I've had a problem with. Since it's traditional that hotels do not include a 13th floor, we're instructed to set the loop in the iteration to SKIP the entire 13th iteration. As I said, I'm fairly new to this, and the only thing that rings a bell is the loop control variable, which, I was told, was partially true.

So anyway, here's my program (that also doesn't compile for some reason), and any help is appreciated (forgive me if I messed anything up by pasting this):

Code:
   char Again = 'y';
   int main()
   {
       while (Again == 'y')
       {
           HotelCalculations();
           print "Do again? y/n\n";
           read Again;
       }
   }
       
   void HotelCalculations()
   {
       int temp = 0;
       int temp2 = 0;
       int count = 2;
       int FloorOccupancy = 0;
       int roomsOccupied = 0;
       int rooms = 0;
       int floors = 0;
       int HotelOccupancy = 0;
       
       print "How many floors are in the hotel?\n";
       print "Floors?\n";
       read floors;
           if (floors > 1)
           {
               print "Since the lobby is on the first floor, the 1st floor will be skipped.\n";
               while (count <= floors)
               {
                   print "How many guest rooms on floor " + count +".\n";
                   print "Rooms?\n";
                   read temp;
                       if (temp >= 10)
                       {
                           print "How many of out of the " + temp + " guest rooms are occupied?\n";
                           read temp2;
                           
                           if (temp >= temp2)
                           {
                               rooms = rooms + temp;
                               roomsOccupied = roomsOccupied + temp2;
                               FloorOccupancy = (temp2 * 100)/temp;
                               print "Floor " + count + " has " + FloorOccupancy + "% Occupancy.\n";
                               count = count + 1;
                           }
                           else
                           {
                               print "ERROR -- Rooms occupied is greater than the number of rooms on floor " + count + ".\n";
                           }
                       }
                       else
                       {
                           print "ERROR -- Need 10 or more rooms on each floor.\n";
                       }
               }
           }
           else
           {
               print "ERROR -- " + floors + " floor is an invalid entry.\n";
           }
       
       if (count - 1 == floors && count - 1 > 1)
       {
       HotelOccupancy = (roomsOccupied * 100)/rooms;
       print "The occupancy of the hotel is " + HotelOccupancy + "%.\n";
       }
   }


My compiler returns the following: "Error: non-function call value". Not only that, but I don't understand how else to "skip" the 13th iteration in the loop without using a loop control variable. I don't know why it's so important, but it's part of the instruction, so I have to do it.

Again, any help is appreciated, and a friendly hello to all you happy programmers.

Reply With Quote
  #2  
Old March 25th, 2005, 06:09 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
[QUOTE Anibal]
PS: Always remember to use the # on the edition bar which wraps the text between the code tags, making the code readable and tabed!
[/QUOTE]

In the name of the Lord....doesn't anybody ever read? Use the code tags. How can we read a code that is not tabbed? Come on!!

Anibal.

Reply With Quote
  #3  
Old March 25th, 2005, 08:57 PM
Rift Rift is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Location: Arizona
Posts: 5 Rift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 48 sec
Reputation Power: 0
Send a message via AIM to Rift Send a message via MSN to Rift Send a message via Yahoo to Rift
Seems I've run into yet another problem. "typedef" isn't recognized by my compiler (VCflat). Visible C-flat is the compiler my instructor suggested we use, since he's the one who created it.

I understand the purpose of typedef, to define a structure and to also create several data types, but if the compiler doesn't recognize it, then I have to find another way around it. Believe me, I had the entire code written out, and just as I hit "compile," 4 hours of hard work = BYE BYE!

Argh, I still need help. :-/

Reply With Quote
  #4  
Old March 25th, 2005, 11:54 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Ask your intrsuctor for typede substitute.
Are all other directives supportted by your C-Flat compiler?

Reply With Quote
  #5  
Old March 26th, 2005, 06:31 AM
Rift Rift is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Location: Arizona
Posts: 5 Rift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 48 sec
Reputation Power: 0
Send a message via AIM to Rift Send a message via MSN to Rift Send a message via Yahoo to Rift
Yeah, any other directives are supported by the compiler. I just get an error when trying to compile with "typedef" since it's expecting a type-declaration.

Reply With Quote
  #6  
Old March 26th, 2005, 10:20 AM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
The only purpose of typedef is to define a new type of data. Instead, just use struct like this:

Code:
   
struct rooms{
  int roomsPerFloor;
  int emptyPerFloor;
}


Off course, when referenced use struct rooms instead of rooms like this:

Code:
   
struct rooms <function name>{
 
  struct rooms thisRooms;
  ...............................
  ...............................
  ...............................
}


Struct is ANSI. If that doesn't work, tell your instructor to get himself another compiler and throw that away!!

Anibal.

Reply With Quote
  #7  
Old March 26th, 2005, 12:25 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Addition to Anibal's advice. For all user defined types, generate a seperate and dedicated header file.Include that file while using user defined type.

It will make things easier for you.

Reply With Quote
  #8  
Old March 27th, 2005, 04:39 AM
Rift Rift is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Location: Arizona
Posts: 5 Rift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 48 sec
Reputation Power: 0
Send a message via AIM to Rift Send a message via MSN to Rift Send a message via Yahoo to Rift
Thanks for the help, but I still don't quite understand how to make this work.

Before I explain, here's a somewhat edited version of the program:

Code:
  // occupancy percentage
  
  
  void procedure()
  {
      int rooms = 0;
      int occupied = 0;
      int occupied2 = 0;
      int calc = 0;
      int rooms2 = 0;    
      int floors = 0;    
      int var2 = 0;
      int var = 2;
          
      print "\nNumber of floors in hotel?\n";
      read floors;
          if(floors <= 1)
          {
              print "    \nPlease enter more than 1.\n";            
          }
              else
              {
                  print "\nFirst floor has no rooms & will be skipped.\n";
              }
                  while(var <= floors)
                  {
                      print "Rooms on floor " + var +":\n";
                      read rooms;
                          if(rooms >= 10)
                          {
                              print "Number occupied out of " + rooms + ":\n";
                              read rooms2;
                          }
                      else
                      {
                          print "Each floor must have at least 10 rooms.\n";
                      }
                          if(rooms >= rooms2)
                          {
                              var2 = var2 + rooms;
                              occupied = occupied + rooms2;
                              calc = (rooms2 * 100)/rooms;
 print "\nPercentage occupancy for room " + var + " is " + calc + "%.\n"; 
                              var = var + 1;
                                      
                              if(var == 13)
                              {
                                  print "Floor 13 will be skipped.\n";
                                  var = var + 1;                                
                              }
                              
                              if(var - 1 == floors && var - 1 > 1)
                              {
                                  occupied2 = (occupied * 100)/rooms;
                                  print "Occupancy is " + occupied2 + "%.\n";
                              }
                          }
                  }
  }
  
  void main()
  {
      char symbol = 'n';
      char doagain = 'y';
      
      while(doagain == 'Y' || doagain == 'y')
      {
          if(symbol == 'N' || symbol == 'n')
          {
              doagain = 'n';
          }
              else
              {
                  doagain = 'y';
              }
          procedure();
          print "Try again?\n";
          read doagain;
      }
  } 


Well as you can see, I didn't particularly achieve much. A lot of it's due to the fact that, not only does our instructor's compiler fail to recognize structured data types, but certain operators that'd make this a lot easier (for example, the member operator, which is nothing more than a simple "."). I also don't have much experience with array declarations and passing them into the functions.

Earlier today, I experimented with:

int floors;
int rooms = 0;
int counter = 0;

print "Number of hotel floors?\n";
read floors;

int roomsAry[floors];

And that's as far as I got. I didn't get much help from the text, as it doesn't clearly (or completely) explain the process of delcaring an array to be passed to a calculating function. For example, it would be one thing if I had:

someValue[1] is 25
someValue[2] holds 36
someValue[3] holds 47

Those are defined elements. What I'm trying to say is that I don't understand how to create an array to pass to the calculating function without having a defined element.

Ugh, hopefully someone understands me. :-( Any help is greatly appreciated.

Reply With Quote
  #9  
Old March 27th, 2005, 01:17 PM
Anibal Anibal is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 176 Anibal User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 20 m 48 sec
Reputation Power: 4
My god!! USE THE CODE TAGS (#)........why doesn't anybody read? It's imposible to read the code that way!!

Example:
Code:
 
#include <stdio.h>
#include <stdlib.h>
 
int *setRooms(int);
 
int main(){
int *blabla;
int floors;
 
printf("How many floors mate:?");
scanf("%d", &floors);
blabla = setRooms(floors);
/* now you have blabla as an int array with as many floors as entered. 
	 You can do with it as you pleased!...call a function to process it, for example */
 
}
 
//this useless function creates the array...you could as well fill it with the info. Hell I don't know.
int *setRooms(int floors){
int *myArray;
myArray = (int*) malloc(floors);
 
/*do whatever you want with the array!! Process it, eat it.....fold it and save it in the closed */
 
return myArray;
}

Good Luck!

ANIbal.

Reply With Quote
  #10  
Old March 27th, 2005, 05:55 PM
Rift Rift is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Location: Arizona
Posts: 5 Rift User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 48 sec
Reputation Power: 0
Send a message via AIM to Rift Send a message via MSN to Rift Send a message via Yahoo to Rift
What's to read? I read the FAQ and saw nothing about code tags. It's not a huge deal, but thanks for the help anyway.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Compilation error and question in regards to iteration


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT