?
Solved

converting a C++ program into a C program format need help please

Posted on 2003-03-30
6
Medium Priority
?
263 Views
Last Modified: 2010-04-15
I have a program which is in c++, and I have to convert it into c language. I try to do some myself, but I get some error messages and the math does not want to calculate.  could anyone help me out, please need some help, anyone
help :(
here are my codes://Programmer: Bernardo Arocho Jr.

#include <iostream.h>
#include <iomanip.h>
#include <stdio.h>

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

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

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

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

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

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

//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( Reservation * );
void Scuba( Reservation * );
void SkyDive( Reservation * );
void Spelunk( Reservation * );
int Menu( void );
void DisplayInfo( const Reservation * );
Package1 DisplayPack1( const Reservation * );
Package2 DisplayPack2( const Reservation * );
Package3 DisplayPack3( const Reservation * );
Package4 DisplayPack4( const Reservation * );

//Main function
main()
{
      int Selection;
   Reservation *Group;
     cout << setprecision( 2 ) << setiosflags( ios::fixed | ios::showpoint );
            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( 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( "%f", Group -> Packs.Climb.Beginners );

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

          Group -> Packs.Climb.Num = Group -> Packs.Climb.Beginners +
                                  Group -> Packs.Climb.Advanced;

      printf( "How many will rent camping equipment? " );
            scanf( "%f", 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( Reservation *Group )
{
      Group -> PackNum = 2;
         printf( "\nScuba Bahama\n" );
      printf( "-------------\n" );
      printf( "How many will be going who need an instructor? " );
            scanf( "%f", Group -> Packs.Scuba.Beginners );

      printf( "How many advanced scuba divers will be going? " );
            scanf( "%f", 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( Reservation *Group )
{
      Group -> PackNum = 3;
         printf( "\nSky Dive Colorado\n" );
      printf( "-------------------\n" );
      printf( "How many will be going? " );
            scanf( "%f", 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( "%f", Group -> Packs.Sky.Lodge1 );

      printf( "How many will stay at Luxury Inn? " );
            scanf( "%f", 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( Reservation *Group )
{
      Group -> PackNum = 4;
         printf( "\nBarron Cliff Spelunk Weekend\n" );
      printf( "------------------------------\n" );
      printf( "How many will be group? " );
            scanf( "%f", Group -> Packs.Spel.Num );

      printf( "How many will rent camping equipment? " );
            scanf( "%f", 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 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
Package1 DisplayPack1( const Reservation *Group )
{
      printf( "Number is party: %f ", Group -> Packs.Climb.Num );
   printf( "Base charges: $%f" , Group -> Packs.Climb.BaseCharges );
   printf( "Instruction Cost: $%f", Group -> Packs.Climb.Instruction );
   printf( "Equipment Rental: $%f", Group -> Packs.Climb.Equipment );
   printf( "Discount: $%f", Group -> Packs.Climb.Discount );
   printf( "Total Charges: $%f", Group -> Packs.Climb.Charges );
   printf( "Required Deposit: $%f", Group -> Packs.Climb.Deposit );

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

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

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

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








0
Comment
Question by:lover7777
[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
6 Comments
 

Author Comment

by:lover7777
ID: 8233326
by the way, if you read this and can not help me thank you for reading anyone and trying to help me.
0
 
LVL 5

Accepted Solution

by:
Kocil earned 100 total points
ID: 8233712
Yeah, your code is too long :)
I foind only some

// #include <iostream.h>   // can not use this on C
// #include <iomanip.h>    // this one too. Just delete them
#include <stdio.h>

....

//Main function
main()
{
  int Selection;
  Reservation *Group;
// cout << setprecision( 2 ) << setiosflags( ios::fixed | ios::showpoint );  // can't use this
// you may use printf("%0.2f", float_var) for the same effect


 

0
 
LVL 2

Expert Comment

by:nahumd
ID: 8233845
This code is actually in C, and not C++ . It does not use object oriented features, and not special C++ libraries.
0
 

Expert Comment

by:DrumRoll
ID: 8265979
Weren't the first implementations of C++ just precompilers for C?
Maybe there are still some around.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 10194628
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by Kocil.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

777 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