?
Solved

having a result problem, need help ASAP Please

Posted on 2003-03-31
5
Medium Priority
?
255 Views
Last Modified: 2010-04-15
I have this program that compiles and everything, but the results low strange and I receive a message saying thread stopped Please I need some serious help. HELP ME :(
here are my codes:
//Programmer: Bernardo Arocho Jr.

#include <stdio.h>
#include <conio.h>

//Climbing package
struct Package1
{
      int Num;
   int Beginners;
   int Advanced;
   int NeedEquip;
   float BaseCharges;
   float Charges;
   float Instruction;
   float Equipment;
   float Discount;
   float Deposit;
 };

//Scuba package
struct Package2
{
      int Num;
   int Beginners;
   int Advanced;
   float BaseCharges;
   float Charges;
   float Instruction;
   float Discount;
   float Deposit;
 };

 //Sky Diving Package
struct Package3
{
      int Num;
   int Lodge1;
   int Lodge2;
   float BaseCharges;
   float Charges;
   float Discount;
   float Lodging;
   float Deposit;
 };

 //Spelunking Package
struct Package4
{
      int Num;
   int NeedEquip;
   float BaseCharges;
   float Charges;
   float Equipment;
   float Discount;
   float Deposit;
 };

 //Combines the four structs
typedef union
{
      struct Package1 Climb;
   struct Package2 Scuba;
   struct Package3 Sky;
   struct Package4 Spel;
 } Pack;

 //Indicates which package is stored
struct Reservation
{
      int PackNum;
   Pack Packs;
 };

//Constants for the charges
const float ClimbRate = 350.0;
const float ScubaRate = 1000.0;
const float SkyDiveRate = 400.0;
const float CaveRate = 700.0;
const float ClimbInstruct = 100.0;
const float ScubaInstruct = 100.0;
const float DailyCampRental = 40.0;
const float DayLodge1 = 65.0;
const float DayLodge2 = 120.0;

//Function prototypes
void Climbing( struct Reservation * );
void Scuba( struct Reservation * );
void SkyDive( struct Reservation * );
void Spelunk( struct Reservation * );
int Menu( void );
void DisplayInfo( const struct Reservation * );
void DisplayPack1( const struct Reservation * );
void DisplayPack2( const struct Reservation * );
void DisplayPack3( const struct Reservation * );
void DisplayPack4( const struct Reservation * );

//Main function
main()
{
      int Selection;
   struct Reservation *Group;
     printf( "%.2f\n" );
            do
         {
               Selection = Menu();
                  switch( Selection )
               {
                     case 1:
                        Climbing( Group );
                           break;
                  case 2:
                        Scuba( Group );
                           break;
                  case 3:
                        SkyDive( Group );
                           break;
                  case 4:
                        Spelunk( Group );
                           break;
                  case 5:
                        printf( "Exiting program.\n\n" );
                }
                      if( Selection < 5 )
                        DisplayInfo( Group );

          } while( Selection != 5 );

      return 0;
 }//end of main()

//Defining the Menu function
int Menu( void )
{
      int Choice;
         do
      {
            printf( "\nHigh Adventure Travel Agency\n" );
         printf( "-----------------------------\n" );
         printf( "1) Devil's Courthouse Adventure Weekend\n" );
         printf( "2) Scuba Bahama\n" );
         printf( "3) Sky Dive Colorado\n" );
         printf( "4) Barron Cliff Spelunk\n" );
         printf( "5) Exit program\n\n" );
               printf( "Enter 1, 2, 3, 4, or 5: " );
                  scanf( "%d", &Choice );
                     if( Choice < 1 || Choice > 5 )
                        printf( "Invalid Selection\n" );

       } while( Choice < 1 || Choice > 5 );

  return Choice;
 }
/******************************************************************************/
//Defining the Climbing function
void Climbing( struct Reservation *Group )
{
       ( *Group ).PackNum = 1;
         printf( "\nDevil's Courthouse Adventure Weekend\n" );
      printf( "--------------------------------------\n" );
      printf( "How many will be going who need an instructor? " );
            scanf( "%d", ( *Group ).Packs.Climb.Beginners );

      printf( "How many advanced climbers will be group? " );
            scanf( "%d", ( *Group ).Packs.Climb.Advanced );

          ( *Group ).Packs.Climb.Num = ( *Group ).Packs.Climb.Beginners +
                                  ( *Group ).Packs.Climb.Advanced;

      printf( "How many will rent camping equipment? " );
            scanf( "%d", ( *Group ).Packs.Climb.NeedEquip );

         //Calculating the charges
      ( *Group ).Packs.Climb.BaseCharges = ( *Group ).Packs.Climb.Num * ClimbRate;
      ( *Group ).Packs.Climb.Charges = ( *Group ).Packs.Climb.BaseCharges;

      //Calculating 10% discount for 5 or more
      if( ( *Group ).Packs.Climb.Num > 4 )
      {
            ( *Group ).Packs.Climb.Discount = ( *Group ).Packs.Climb.Charges * .10;
         ( *Group ).Packs.Climb.Charges -= ( *Group ).Packs.Climb.Discount;
       }
      else
            ( *Group ).Packs.Climb.Discount = 0;

      //Adding cost of Instruction
      ( *Group ).Packs.Climb.Instruction = ( *Group ).Packs.Climb.Beginners * ClimbInstruct;
      ( *Group ).Packs.Climb.Charges += ( *Group ).Packs.Climb.Instruction;

      //Adding the cost of the camping equipment
      ( *Group ).Packs.Climb.Equipment = ( *Group ).Packs.Climb.NeedEquip * DailyCampRental * 4;
      ( *Group ).Packs.Climb.Charges += ( *Group ).Packs.Climb.Equipment;

      //Calculating the deposit
      ( *Group ).Packs.Climb.Deposit = ( *Group ).Packs.Climb.Charges/2.0;
 }//end of Climbing()
/******************************************************************************/
//Defining Scuba function
void Scuba( struct Reservation *Group )
{
      ( *Group ).PackNum = 2;
         printf( "\nScuba Bahama\n" );
      printf( "-------------\n" );
      printf( "How many will be going who need an instructor? " );
            scanf( "%d", ( *Group ).Packs.Scuba.Beginners );

      printf( "How many advanced scuba divers will be going? " );
            scanf( "%d", ( *Group ).Packs.Scuba.Advanced );

          ( *Group ).Packs.Scuba.Num = ( *Group ).Packs.Scuba.Beginners +
                                  ( *Group ).Packs.Scuba.Advanced;

      //Calculating base charges
      ( *Group ).Packs.Scuba.BaseCharges = ( *Group ).Packs.Scuba.Num * ScubaRate;
      ( *Group ).Packs.Scuba.Charges = ( *Group ).Packs.Scuba.BaseCharges;

      //Calculating 10% discount for 5 or more
      if( ( *Group ).Packs.Scuba.Num > 4 )
      {
            ( *Group ).Packs.Scuba.Discount = ( *Group ).Packs.Scuba.Charges * .10;
         ( *Group ).Packs.Scuba.Charges -= ( *Group ).Packs.Scuba.Discount;
       }
      else
            ( *Group ).Packs.Scuba.Discount = 0;

      //Adding the cost for Instruction
      ( *Group ).Packs.Scuba.Instruction = ( *Group ).Packs.Scuba.Beginners * ScubaInstruct;
      ( *Group ).Packs.Scuba.Charges += ( *Group ).Packs.Scuba.Instruction;

      //Calculating the deposit
      ( *Group ).Packs.Scuba.Deposit = ( *Group ).Packs.Scuba.Charges/2.0;
 }//end of Scuba()
/******************************************************************************/
//Defining Sky Dive function
void SkyDive( struct Reservation *Group )
{
      ( *Group ).PackNum = 3;
         printf( "\nSky Dive Colorado\n" );
      printf( "-------------------\n" );
      printf( "How many will be going? " );
            scanf( "%d", ( *Group ).Packs.Sky.Num );

      //Calculating base charges
      ( *Group ).Packs.Sky.BaseCharges = ( *Group ).Packs.Sky.Num * SkyDiveRate;
      ( *Group ).Packs.Sky.Charges = ( *Group ).Packs.Sky.BaseCharges;

      //Calculating 10% discount for 5 or more
      if( ( *Group ).Packs.Sky.Num > 4 )
      {
            ( *Group ).Packs.Sky.Discount = ( *Group ).Packs.Sky.Charges * .10;
         ( *Group ).Packs.Sky.Charges -= ( *Group ).Packs.Sky.Discount;
       }
      else
            ( *Group ).Packs.Sky.Discount = 0;

      //Calculating lodging costs
      printf( "How many will stay at Wilderness Lodge? " );
            scanf( "%d", ( *Group ).Packs.Sky.Lodge1 );

      printf( "How many will stay at Luxury Inn? " );
            scanf( "%d", ( *Group ).Packs.Sky.Lodge2 );

          ( *Group ).Packs.Sky.Lodging = ( ( *Group ).Packs.Sky.Lodge1 * DayLodge1 ) +
                                    ( ( *Group ).Packs.Sky.Lodge2 * DayLodge2 );

      //Calculating deposit
      ( *Group ).Packs.Sky.Deposit = ( *Group ).Packs.Sky.Charges/2.0;

 }//end of SkyDive function
/******************************************************************************/
//Defining Spelunk function
void Spelunk( struct Reservation *Group )
{
      ( *Group ).PackNum = 4;
         printf( "\nBarron Cliff Spelunk Weekend\n" );
      printf( "------------------------------\n" );
      printf( "How many will be group? " );
            scanf( "%d", ( *Group ).Packs.Spel.Num );

      printf( "How many will rent camping equipment? " );
            scanf( "%d", ( *Group ).Packs.Spel.NeedEquip );

      //Calculating base charges
      ( *Group ).Packs.Spel.BaseCharges = ( *Group ).Packs.Spel.Num * CaveRate;
      ( *Group ).Packs.Spel.Charges = ( *Group ).Packs.Spel.BaseCharges;

      //Calculating 10% discount for 5 or more
      if( ( *Group ).Packs.Spel.Num > 4 )
      {
            ( *Group ).Packs.Spel.Discount = ( *Group ).Packs.Spel.Charges * .10;
         ( *Group ).Packs.Spel.Charges -= ( *Group ).Packs.Spel.Discount;
       }
      else
            ( *Group ).Packs.Spel.Discount = 0;

      //Adding the cost of the camping equipment rental
      ( *Group ).Packs.Spel.Equipment = ( *Group ).Packs.Spel.NeedEquip * DailyCampRental * 4;
      ( *Group ).Packs.Spel.Charges += ( *Group ).Packs.Spel.Equipment;

      //Calculating deposit
      ( *Group ).Packs.Spel.Deposit = ( *Group ).Packs.Spel.Charges/2.0;

 }//end of Spelunk function
/******************************************************************************/
//Defining DisplayInfo function
void DisplayInfo( const struct Reservation *Group )
{
      switch( ( *Group ).PackNum )
   {
         case 1:
            DisplayPack1( Group );
               break;
      case 2:
            DisplayPack2( Group );
               break;
      case 3:
            DisplayPack3( Group );
               break;
      case 4:
            DisplayPack4( Group );
               break;
      default:
            printf( "ERROR: Invalid package number.\n" );
    }

 }//end of DisplayInfo function
/******************************************************************************/
//Defining DisplayPack1 function
void DisplayPack1( const struct Reservation *Group )
{
      printf( "Number is party: %d\n", (* Group ).Packs.Climb.Num );
   printf( "Base charges: $%d\n" , ( *Group ).Packs.Climb.BaseCharges );
   printf( "Instruction Cost: $%d\n", ( *Group ).Packs.Climb.Instruction );
   printf( "Equipment Rental: $%d\n", ( *Group ).Packs.Climb.Equipment );
   printf( "Discount: $%d\n", ( *Group ).Packs.Climb.Discount );
   printf( "Total Charges: $%d\n", ( *Group ).Packs.Climb.Charges );
   printf( "Required Deposit: $%d\n", ( *Group ).Packs.Climb.Deposit );

 }//end of DisplayPack1 function
/******************************************************************************/
//Defining DisplayPack2 function
void DisplayPack2( const struct Reservation *Group )
{
      printf( "Number is party: %d\n", ( *Group ).Packs.Scuba.Num );
   printf( "Base charges: $%d\n", ( *Group ).Packs.Scuba.BaseCharges );
   printf( "Instruction Cost: $%d\n", ( *Group ).Packs.Scuba.Instruction );
   printf( "Discount: $%d\n", ( *Group ).Packs.Scuba.Discount );
   printf( "Total Charges: $%d\n", ( *Group ).Packs.Scuba.Charges );
   printf( "Required Deposit: $%d\n", ( *Group ).Packs.Scuba.Deposit );

 }//end of DisplayPack2 function
/******************************************************************************/
//Defining DisplayPack3 function
void DisplayPack3( const struct Reservation *Group )
{
      printf( "Number is party: %d\n", ( *Group ).Packs.Sky.Num );
   printf( "Base charges: $%d\n", ( *Group ).Packs.Sky.BaseCharges );
   printf( "Lodging: $%d\n", ( *Group ).Packs.Sky.Lodging );
   printf( "Discount: $%d\n", ( *Group ).Packs.Sky.Discount );
   printf( "Total Charges: $%d\n", ( *Group ).Packs.Sky.Charges );
   printf( "Required Deposit: $%d\n", ( *Group ).Packs.Sky.Deposit );

 }//end of DisplayPack3 function
/******************************************************************************/
//Defining DisplayPack4 function
void DisplayPack4( const struct Reservation *Group )
{
      printf( "Number is party: %d\n", ( *Group ).Packs.Spel.Num );
      printf( "Base charges: $%d\n", ( *Group ).Packs.Spel.BaseCharges );
   printf( "Equipment Rental: $%d\n", ( *Group ).Packs.Spel.Equipment );
   printf( "Discount: $%d\n", ( *Group ).Packs.Spel.Discount );
   printf( "Total Charges: $%d\n", ( *Group ).Packs.Spel.Charges );
   printf( "Required Deposit: $%d\n", ( *Group ).Packs.Spel.Deposit );

 }//end of DisplayPack4 function
/******************************************************************************/








0
Comment
Question by:sirtrunks
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Author Comment

by:sirtrunks
ID: 8243691
thank you for all those who help me out, I thank you all
0
 
LVL 1

Expert Comment

by:sarda_ramesh
ID: 8244397
hi there
  i cant understand what ur problem is . I have tried to run the code using Turboc3 compiler and its working fine ..

regards
ramesh
0
 
LVL 2

Accepted Solution

by:
corduroy9 earned 60 total points
ID: 8247180

Well, one thing right off, in the Main function you are defining and sending the struct Reservation *Group as a pointer...pointers are only 4 bytes (depending on system) and hold an address, so when you go into a function and receive the structure as a pointer, and try to do something like this,

( *Group ).PackNum = 1;  

you're bound to be hitting memory that you haven't allocated yet.  Why don't you define the structure as follows:

struct Reservation Group = {NULL};

Then pass in the address with the & operator.

I haven't looked past this problem because your program is bombing so quickly.

Good luck...
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question