Thread: Assistance Please?

  1. #1
    Silence
    Guest

    Unhappy Assistance Please?

    Hey all,

    Im having a lot of problems with a program that i have to write.
    Basically the program accepts a room number, name, number of people booking is for and a destination. (Max = 10 people) It then calculates the costs of the trip and puts the passengers into suitable transport arrangements e.g. mini_bus etc.

    I have it down to 11 errors, 14 warnings, but most of the errors are
    '>=' : 'int [10]' differs in levels of indirection from 'const int '

    i have no idea what this is, maybe something with the arrays, not sure.

    Could someone have a look at this and maybe tell me what im doing wrong?

    Also if there is anything else you spot that is wrong i would appreciate if you could tell me how to fix it.

    Sorry to put all the code in but i dont know where the probs are

    Thanks to anyone that puts time aside for this.
    Here is the code

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

    #define SIZE 10

    /* Declare Ints etc. Here */

    void instructions (void);
    void summary (void);
    void close (void);

    char name[SIZE][20];
    char destination[SIZE];
    int room_number[SIZE];
    int num_people[SIZE];
    int i=0;
    int choice;

    int air_st_cost = 0, air_lt_cost = 0, air_mb_cost = 0, train_st_cost =0,train_lt_cost =0, train_mb_cost = 0; /* Floating point integers*/
    int city_st_cost = 0, city_lt_cost = 0, city_mb_cost = 0, total;

    int num_st_air = 0, num_lt_air = 0, num_mb_air = 0, num_st_train = 0, num_lt_train = 0, num_mb_train = 0;
    int num_st_city = 0, num_lt_city = 0, num_mb_city = 0;

    int remainder_air = 0, remainder_train = 0, remainder_city = 0;

    int num_ppl_air = 0, num_ppl_train = 0, num_ppl_city = 0;


    //************************************************** *
    main()

    {

    void instructions (void);

    void summary (void);

    void close (void);

    return 0;

    }
    //************************************************** *

    void instructions (void){

    for (i=0;i<=SIZE-1;i++)
    {
    printf("Enter Name:");
    scanf("%c", &name[i]);
    fflush(stdin);
    printf ("\nEnter The Room Number: ");
    scanf ("%d",&room_number[i]);
    fflush(stdin);
    printf ( "Enter the number of people you are booking for:" );
    scanf ("%d", &num_people[i]);
    printf ( "\t\t***************************\n\a" );
    printf ( "\t\tDestination for Paseenger #\n" );
    printf ( "\t\t***************************\n\n\n" );
    printf ( "\tA:" );
    printf ( "\t\tAirport\n\n" );
    printf ( "\tB:" );
    printf ( "\t\tTrainstation\n\n" );
    printf ( "\tC:" );
    printf ( "\t\tCity\n\n" );
    scanf ("%c", &destination[i]);
    i++;


    //************************************************** *
    //**************************************************


    switch (destination) {/* Switch for incrementation and calculation of destinations and vehicles to those destinations */

    case 'A' : case 'a':

    {
    if (num_people[i] > 15)
    num_mb_air += num_people[i] / 15;
    num_people[i] %= 15;


    if (( num_people[i] >= 1 ) && ( num_people[i] <= 3 )) /* Tests conditions according to taxi specifications*/
    num_st_air++;
    if (( num_people[i] >= 4 ) && ( num_people[i] <= 6 ))
    num_lt_air++;
    if (( num_people[i] >=7 ) && ( num_people[i] <= 15 ))
    num_mb_air++;

    }

    else

    num_ppl_air += num_people[i];

    break;

    //************************************************** *

    case 'B' : case 'b': /* Switch enabling train station function */


    {

    if (num_people > 15)
    num_mb_train += num_people / 15;
    num_people %= 15;


    if (( num_people >= 1 ) && ( num_people <= 3 )) /* Tests conditions according to taxi specifications*/
    num_st_train++;
    if (( num_people >= 4 ) && ( num_people <= 6 ))
    num_lt_train++;
    if (( num_people >= 7 ) && ( num_people <= 15 ))
    num_mb_train++;
    }

    else
    num_ppl_train += num_people;

    break;

    //************************************************** *

    case 'C' : case 'c': /* Switch enabling city function */

    {
    if (num_people > 15)
    num_mb_city += num_people / 15;
    num_people %= 15;


    if (( num_people >= 1 ) && ( num_people <= 3 )) /* Tests conditions according to taxi specifications*/
    num_st_city++;
    if (( num_people >= 4 ) && ( num_people <= 6 ))
    num_lt_city++;
    if (( num_people >= 7 ) && ( num_people <= 15 ))
    num_mb_city++;
    }


    num_ppl_city += num_people;

    break;

    //************************************************** ************************************************** **********


    default:
    printf ( "\t---------------------------------\n"); /* Destination specification not valid */
    printf ( "\t Wrong Destination Entered.\n\n ");
    printf ( "\t---------------------------------\n");


    //************************************************** ************************************************** **********

    printf("Do you want to change the information that you have just entered? (Y/N)\n"); /* Prompt user decision to change previous input - Yes or No*/
    scanf("%c", &choice);

    if ((choice == 'Y') || (choice == 'y'))
    --i;

    }

    /*)*/break;

    }

    while ( choice != 'Y' || 'y' );

    num_mb_air += ( num_ppl_air / 15 );
    remainder_air = num_ppl_air % 15;

    if (( remainder_air >=1) && ( remainder_air <=3))
    num_st_air++;
    else if (( remainder_air >= 4) && ( remainder_air <= 6))
    num_lt_air++;
    else if (( remainder_air >= 7) && ( remainder_air <= 15))
    num_mb_air++;

    num_mb_train += ( num_ppl_train / 15 );
    remainder_train += num_ppl_train % 15 ;

    if (( remainder_train >=1) && ( remainder_train <=3))
    num_st_train++;
    else if (( remainder_train >= 4) && ( remainder_train <= 6))
    num_lt_train++;
    else if (( remainder_train >= 7) && ( remainder_train <= 15))
    num_mb_train++;

    num_mb_city += ( num_ppl_city / 15 );
    remainder_city += num_ppl_city % 15 ;

    if (( remainder_city >=1) && ( remainder_city <=3))
    num_st_city++;
    else if (( remainder_city >= 4) && ( remainder_city <= 6))
    num_lt_city++;
    else if (( remainder_city >= 7) && ( remainder_city <= 15))
    num_mb_city++;

    air_st_cost = num_st_air * 60; /* Calculates the value of destination costs */
    air_lt_cost = num_lt_air * 100;
    air_mb_cost = num_mb_air * 140;
    train_st_cost = num_st_train * 45;
    train_lt_cost = num_lt_train * 70;
    train_mb_cost = num_mb_train * 110;
    city_st_cost = num_st_city * 30;
    city_lt_cost = num_lt_city * 50;
    city_mb_cost = num_mb_city * 70;
    total = air_st_cost + air_lt_cost + air_mb_cost + train_st_cost + train_lt_cost + train_mb_cost + city_st_cost + city_lt_cost + city_mb_cost; /* Calculates total variable value for output */


    }

    return;
    }
    //************************************************** *******************************

    void summary (void){


    total = air_st_cost + air_lt_cost + air_mb_cost + train_st_cost + train_lt_cost + train_mb_cost + city_st_cost + city_lt_cost + city_mb_cost; /* Calculates total variable value for output */
    printf ( "\n\n" );
    printf ( "************************************************* ****************");
    printf ( "\n\n" );
    /* Displays the final summary */
    printf ("%22s\t%d\t%d\t%s\n", names[i],room_number[i],num_bookings[i],destination[i]);
    printf ( "Type of Transport\tConferees\tDestination\tNumber Required\tCost\n" );
    printf ( "*****************\t*********\t***********\t****** *********\t****\n" );
    printf ( "*****************\t*********\t***********\t****** *********\t****\n" );
    printf ( "\n\n" );
    printf ( "Small Taxi \tAirport \t%7d%11c%7.2f\n", num_st_air, '$', air_st_cost);
    printf ( "Large Taxi \tAirport \t%7d%11c%7.2f\n", num_lt_air, '$', air_lt_cost);
    printf ( "Mini Bus \tAirport \t%7d%11c%7.2f\n", num_mb_air, '$', air_mb_cost);
    printf ( "Small Taxi \tTrain Station\t%7d%11c%7.2f\n", num_st_train, '$', train_st_cost);
    printf ( "Large Taxi \tTrain Station\t%7d%11c%7.2f\n", num_lt_train, '$', train_lt_cost);
    printf ( "Mini Bus \tTrain Station\t%7d%11c%7.2f\n", num_mb_train, '$', train_mb_cost);
    printf ( "Small Taxi \tCity \t%7d%11c%7.2f\n", num_st_city, '$', city_st_cost);
    printf ( "Large Taxi \tCity \t%7d%11c%7.2f\n", num_lt_city, '$', city_lt_cost);
    printf ( "Mini Mini \tCity \t%7d%11c%7.2f\n", num_mb_city, '$', city_mb_cost);
    printf ( "\n\n\a" );
    printf ("%66s\n", "*********" );
    printf ("\tTotal Cost %39c%7.2f\n", '$',total);
    printf ("%66s\n", "*********" );
    getch ();







    return;
    }
    //************************************************** *******************************



    void close (void){

    printf("In closing sequence\n\n\n");

    return;

    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Please can you use code tags when posting code, your code here is pretty much unreadable without a lot of reformatting.

    From a quick look:
    >There's a switch(destination). destination is an array, and you shouldn't switch on it, maybe you omitted a subscript eg destination[0] ?

    >Same kinda a thing, but when using num_people.

    >My compiler warns of a whole load of misplaced else statements. I'll leave those to you to sort out.

    There might be more but I can't tell 'cos of the formatting.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    11

    re assistance

    hello there,
    I had a look at your program, I am not sure exactly what you are trying to do, however it compiles now and thats a start, if you compare mine to yours you will see the adjustments i made , many of these were just rougue asterisks not comented out properly, and some wrong variable names. It will not run right through you will just have to go through it line by line. Maybe someone else will be able to help you as i am off on holiday tomorrow and can't spend anymore time on it.

    If i were you i would get it up and running then rearrange it so that you are not calling all the functions from main, get main to call the intro screen and menu then call the other functions from each other , and no the code is not tagged , oh and they just
    love scanf and fflush on here. Oh yes i used dev c++ compiler from www.bloodshed.net for this i didn't try it on any other.

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

    #define SIZE 10

    /* Declare Ints etc. Here */

    void instructions(void);
    void summary(void);
    void close(void);

    char name[SIZE][20];
    char destination; /*[SIZE];*/
    int room_number[SIZE];
    int num_people[SIZE];
    int i=0;
    int choice;

    int air_st_cost = 0, air_lt_cost = 0, air_mb_cost = 0, train_st_cost =0,train_lt_cost =0, train_mb_cost = 0; /* Floating point integers*/
    int city_st_cost = 0, city_lt_cost = 0, city_mb_cost = 0, total;

    int num_st_air = 0, num_lt_air = 0, num_mb_air = 0, num_st_train = 0, num_lt_train = 0, num_mb_train = 0;
    int num_st_city = 0, num_lt_city = 0, num_mb_city = 0;

    int remainder_air = 0, remainder_train = 0, remainder_city = 0;

    int num_ppl_air = 0, num_ppl_train = 0, num_ppl_city = 0;


    // **************************************************

    int main()

    {

    instructions();

    summary();

    close();

    return(0);

    }
    // **************************************************


    void instructions()
    {
    for (i=0;i<=SIZE-1;i++)
    {
    printf("Enter Name:");
    scanf("%c", &name[i]);
    fflush(stdin);
    printf ("\nEnter The Room Number: ");
    scanf ("%d",&room_number[i]);
    fflush(stdin);
    printf ( "Enter the number of people you are booking for:" );
    scanf ("%d", &num_people[i]);
    fflush(stdin);
    printf ( "\t\t***************************\n\a" );
    printf ( "\t\tDestination for Passenger #\n" );
    printf ( "\t\t***************************\n\n\n" );
    printf ( "\tA:" );
    printf ( "\t\tAirport\n\n" );
    printf ( "\tB:" );
    printf ( "\t\tTrainstation\n\n" );
    printf ( "\tC:" );
    printf ( "\t\tCity\n\n" );
    scanf ("%c", &destination/*[i]*/);
    fflush(stdin);
    }


    // **************************************************

    // **************************************************



    switch(destination) {/* Switch for incrementation and calculation of destinations and vehicles to those destinations */

    case 'A': case 'a':

    {
    if (num_people[i] > 15)
    {
    num_mb_air += num_people[i] / 15;
    num_people[i] %= 15;
    }

    if (( num_people[i] >= 1 ) && ( num_people[i] <= 3 )) /* Tests conditions according to taxi specifications*/
    num_st_air++;
    if (( num_people[i] >= 4 ) && ( num_people[i] <= 6 ))
    num_lt_air++;
    if (( num_people[i] >=7 ) && ( num_people[i] <= 15 ))
    num_mb_air++;



    else
    {
    num_ppl_air += num_people[i];
    }
    break;

    // **************************************************


    case 'B' : case 'b': /* Switch enabling train station function */


    {

    if (num_people[i] > 15)
    num_mb_train += num_people[i] / 15;
    num_people[i] %= 15;


    if (( num_people[i] >= 1 ) && ( num_people[i] <= 3 )) /* Tests conditions according to taxi specifications*/
    num_st_train++;
    if (( num_people[i] >= 4 ) && ( num_people[i] <= 6 ))
    num_lt_train++;
    if (( num_people[i] >= 7 ) && ( num_people[i] <= 15 ))
    num_mb_train++;


    else
    num_ppl_train += num_people[i];

    break;

    // **************************************************


    case 'C' : case 'c': /* Switch enabling city function */

    {
    if (num_people[i] > 15)
    num_mb_city += num_people[i] / 15;
    num_people[i] %= 15;


    if (( num_people[i] >= 1 ) && ( num_people[i] <= 3 )) /* Tests conditions according to taxi specifications*/
    num_st_city++;
    if (( num_people[i] >= 4 ) && ( num_people[i] <= 6 ))
    num_lt_city++;
    if (( num_people[i] >= 7 ) && ( num_people[i] <= 15 ))
    num_mb_city++;
    }


    num_ppl_city += num_people[i];

    break;

    // **************************************************



    default:
    printf ( "\t---------------------------------\n"); /* Destination specification not valid */
    printf ( "\t Wrong Destination Entered.\n\n ");
    printf ( "\t---------------------------------\n");


    /* ************************************************** */

    printf("Do you want to change the information that you have just entered? (Y/N)\n"); /* Prompt user decision to change previous input - Yes or No*/
    scanf("%c", &choice);

    if ((choice == 'Y') || (choice == 'y'))
    --i;
    }


    /*)*/break;

    }

    while ( choice != 'Y' || 'y' );

    num_mb_air += ( num_ppl_air / 15 );
    remainder_air = num_ppl_air % 15;

    if (( remainder_air >=1) && ( remainder_air <=3))
    num_st_air++;
    else if (( remainder_air >= 4) && ( remainder_air <= 6))
    num_lt_air++;
    else if (( remainder_air >= 7) && ( remainder_air <= 15))
    num_mb_air++;

    num_mb_train += ( num_ppl_train / 15 );
    remainder_train += num_ppl_train % 15 ;

    if (( remainder_train >=1) && ( remainder_train <=3))
    num_st_train++;
    else if (( remainder_train >= 4) && ( remainder_train <= 6))
    num_lt_train++;
    else if (( remainder_train >= 7) && ( remainder_train <= 15))
    num_mb_train++;

    num_mb_city += ( num_ppl_city / 15 );
    remainder_city += num_ppl_city % 15 ;

    if (( remainder_city >=1) && ( remainder_city <=3))
    num_st_city++;
    else if (( remainder_city >= 4) && ( remainder_city <= 6))
    num_lt_city++;
    else if (( remainder_city >= 7) && ( remainder_city <= 15))
    num_mb_city++;

    air_st_cost = num_st_air * 60; /* Calculates the value of destination costs */
    air_lt_cost = num_lt_air * 100;
    air_mb_cost = num_mb_air * 140;
    train_st_cost = num_st_train * 45;
    train_lt_cost = num_lt_train * 70;
    train_mb_cost = num_mb_train * 110;
    city_st_cost = num_st_city * 30;
    city_lt_cost = num_lt_city * 50;
    city_mb_cost = num_mb_city * 70;
    total = air_st_cost + air_lt_cost + air_mb_cost + train_st_cost + train_lt_cost + train_mb_cost + city_st_cost + city_lt_cost + city_mb_cost; /* Calculates total variable value for output */


    }

    return;
    }
    /************************************************** **/

    void summary(void)
    {

    total = air_st_cost + air_lt_cost + air_mb_cost + train_st_cost + train_lt_cost + train_mb_cost + city_st_cost + city_lt_cost + city_mb_cost; /* Calculates total variable value for output */
    printf ( "\n\n" );
    printf ( " ************************************************** ");
    printf ( "\n\n" );
    /* Displays the final summary */
    printf ("%22s\t%d\t%d\t%s\n", name[i],room_number[i],num_people[i],destination);
    printf ( "Type of Transport\tConferees\tDestination\tNumber Required\tCost\n" );
    printf ( " *****************\t*********\t***********\t*******
    ********\t****\n" );
    printf ( " *****************\t*********\t***********\t*******
    ********\t****\n" );
    printf ( "\n\n" );
    printf ( "Small Taxi \tAirport \t%7d%11c%7.2f\n", num_st_air, '$', air_st_cost);
    printf ( "Large Taxi \tAirport \t%7d%11c%7.2f\n", num_lt_air, '$', air_lt_cost);
    printf ( "Mini Bus \tAirport \t%7d%11c%7.2f\n", num_mb_air, '$', air_mb_cost);
    printf ( "Small Taxi \tTrain Station\t%7d%11c%7.2f\n", num_st_train, '$', train_st_cost);
    printf ( "Large Taxi \tTrain Station\t%7d%11c%7.2f\n", num_lt_train, '$', train_lt_cost);
    printf ( "Mini Bus \tTrain Station\t%7d%11c%7.2f\n", num_mb_train, '$', train_mb_cost);
    printf ( "Small Taxi \tCity \t%7d%11c%7.2f\n", num_st_city, '$', city_st_cost);
    printf ( "Large Taxi \tCity \t%7d%11c%7.2f\n", num_lt_city, '$', city_lt_cost);
    printf ( "Mini Mini \tCity \t%7d%11c%7.2f\n", num_mb_city, '$', city_mb_cost);
    printf ( "\n\n\a" );
    printf ("%66s\n", "*********" );
    printf ("\tTotal Cost %39c%7.2f\n", '$',total);
    printf ("%66s\n", "*********" );
    getch ();







    return;
    }
    /************************************************** */



    void close(void){

    printf("In closing sequence\n\n\n");

    return;

    }
    If its not 5.00p.m. on Friday its crap!!

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    > and no the code is not tagged , oh and they just love scanf and fflush on here
    So why didn't you put the tags on when you posted it again then?

    The only people that love scanf() and fflush() are the newbies who have lame teachers telling them to do things that way. The advice given by people here is to steer clear of such functions because they are bad news. Its a shame that teachers feel the need to start of badly
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274
    whats wrong with scanf? i havn't had any problems with it yet, but then again i haven't been programming for long.

  6. #6
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >The only people that love scanf() and fflush() are the newbies
    >who have lame teachers telling them to do things that way.
    There's nothing wrong with fflush as long as you understand that it only works predictably for output streams. The scanf function loses it's usefulness after better methods are learned since it's really only good for file redirection which isn't terribly useful.

    >Its a shame that teachers feel the need to start of badly
    I've come to the conclusion that they don't know any better.

    >whats wrong with scanf?
    In practice, scanf tends to be buggy with string data, but the biggest problem is that it handles formatted input yet is mainly used for user input. In my opinion this is stupid because user input is *never* formatted correctly. So for user input fgets and the appropriate parsing routine is better while the scanf family is better used for files and standard input redirected from files.

    -Prelude
    My best code is written with the delete key.

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >There's nothing wrong with fflush as long as you understand that it only works predictably for output streams.
    That is what I meant, but I didn't make it clear Thanks for clarifying.

    >scanf... In my opinion this is stupid because user input is *never* formatted correctly.
    Totally agree, anything outside of your program is volatile, and should be treated with a degree of care. My advice (not that you need it Prelude!), don't trust input to be correct, even if you're sure that 99% of the time it will be.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    May 2002
    Posts
    3
    thanks everyone 4 your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hello,i need assistance in completing the code
    By toader in forum C++ Programming
    Replies: 1
    Last Post: 06-22-2009, 03:32 AM
  2. Variable Timer assistance
    By rich2852 in forum C Programming
    Replies: 2
    Last Post: 01-21-2009, 05:43 AM
  3. Any assistance would be greatly appreciated
    By iiwhitexb0iii in forum C Programming
    Replies: 18
    Last Post: 02-26-2006, 12:06 PM
  4. Need some more assistance
    By Thantos in forum Windows Programming
    Replies: 6
    Last Post: 08-14-2003, 12:13 PM
  5. Need assistance for major text base Arena RPG project
    By Ruflano in forum C++ Programming
    Replies: 0
    Last Post: 04-04-2002, 11:11 AM