Thread: easy if you know how to use functions...

  1. #1
    Unregistered
    Guest

    easy if you know how to use functions...

    sorry guys...it's been awhile....i can't figure out how to link these functions together....our teacher doesn't want use to put anything in main that has to do with the program......i might have a lot wrong w/ it syntatically and logically...if anyone can help me in anyway it'd be very helpful.....here's the code i have so far...

    *Vincent Irick*/
    /*Lab 1*/
    /*This lab gives the user the choice of 4 different vacations plans. The user inputs the
    number of people in the group and also the number of days. The user is then given the base amount
    the have to deposit and the amount per person*/

    #include <stdio.h>

    int intro(int, int, int); /*the intro function prototype*/
    int devils(int, int, int, int, int, int, int); /*the devils function prototype*/
    int scuba(int, int, int, int); /*the scuba function prototype*/
    int skydive(int, int, int, int, int, int, int, int); /*skydive function prototype*/
    int baron(int, int, int, int, int); /*baron function prototype*/

    void main(void)
    {
    }

    int intro(int x, int y, int z)
    {
    printf("Hi, Welcome to the High Adventure Agency. Please select a vacation package");
    printf("\n\nDevil's Courthourse Adventure Weekend");
    printf("An action packed three days weekend camping trip in North Carolina");
    printf("\nScuba Bahama");
    printf("\n\n A week-long cruise to Bahama with three days of scuba diving");
    printf("\nThe Sky Dive Colorado");
    printf("\n\n Four thrilling days with expert sky diving instructors in Colorado Springs");
    printf("\nBaron Cliff");
    printf("\n\nEight days spent hiking and exporing caves in the Baron Cliff Wilderness");
    printf("Please select a vacation package by entering the first letter in lowercase");
    scanf("%c", &x);
    if (x == 'd')
    devils(x, y, z);
    if (x == 's');
    scuba(x, y);
    if (x == 't')
    skydive(x, y, z);
    if (x == 'b')
    baron(x, y);
    }

    int devils(int x, int y, int z, int day1, int base, int equipment, int instruction)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need climbing instruction?");
    scanf("%d", &y);
    printf("\nHow many people need to rent equipment?");
    scanf("%d", &z);
    printf("How many days?");
    scanf("%d", &day1);

    base = (x * 350);
    instruction = (y * 100);
    equipment = (z * 40 * day1);
    }

    int scuba(int x, int y, int base, int instruction)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need scuba instruction?");
    scanf("%d", &y);

    base = (x * 1000);
    instruction = (y * 100);
    }

    int skydive(int x, int y, int z, int base, int lodge, int inn, int day1, int day2)
    {


    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people are going to be staying in the Wilderness Lodge?");
    scanf("%d", &y);
    printf("\nHow many people will be staying at the Luxury Inn?");
    scanf("%d", &z);
    printf("\nHow many days?");
    scanf("%d", day1);
    printf("How many days?");
    scanf"%d", day2);
    base = x * 400;
    lodge = (y * 65 * day1);
    inn = (x * 120 * day2);

    }

    int baron(int x, int y, int day1, int base, int equipment)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need to rent equipment?");
    scanf("%d", &z);
    printf("How many days?");
    scanf("%d", &day1);

    base = (x * 700);
    equipment = (y * 40 * day1);

    }

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >our teacher doesn't want use to put anything in main that has
    >to do with the program

    I think your teacher means: don't put the content of what could be in functions into the main.

    But the main sure needs to contain the functions, since in this way it doesn't do anything.

    A hint: try to find out what the functions actually do and create a flow chart where you use the functions as black boxes. This flow chart can be implemented in the main.

  3. #3
    Unregistered
    Guest
    k, i'll definitely try that and get back to u....

  4. #4
    Unregistered
    Guest
    /*Vincent Irick*/
    /*Lab 1*/
    /*This lab gives the user the choice of 4 different vacations plans. The user
    inputs the
    number of people in the group and also the number of days. The user is then
    given the base amount
    the have to deposit and the amount per person*/

    #include <stdio.h>

    int devils(int, int, int, int, int, int, int); /*the devils function
    prototype*/
    int scuba(int, int, int, int); /*the scuba function prototype*/
    int skydive(int, int, int, int, int, int, int, int); /*skydive function
    prototype*/
    int baron(int, int, int, int, int); /*baron function prototype*/

    void main()
    {
    int x, y ,z;

    printf("Hi, Welcome to the High Adventure Agency. Please select a vacation package");
    printf("\n\nDevil's Courthourse Adventure Weekend");
    printf("An action packed three days weekend camping trip in North Carolina");
    printf("\nScuba Bahama");
    printf("\n\n A week-long cruise to Bahama with three days of scuba diving");
    printf("\nThe Sky Dive Colorado");
    printf("\n\n Four thrilling days with expert sky diving instructors in Colorado Springs");
    printf("\nBaron Cliff");
    printf("\n\nEight days spent hiking and exporing caves in the Baron Cliff Wilderness");
    printf("Please select a vacation package by entering the first letter in lowercase");
    scanf("%c", &x);
    if (x == 'd')
    devils(x, y, z);
    if (x == 's');
    scuba(x, y);
    if (x == 't')
    skydive(x, y, z);
    if (x == 'b')
    baron(x, y);
    }


    int devils(int x, int y, int z, int day1, int base, int equipment, int
    instruction)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need climbing instruction?");
    scanf("%d", &y);
    printf("\nHow many people need to rent equipment?");
    scanf("%d", &z);
    printf("How many days?");
    scanf("%d", &day1);

    base = (x * 350);
    instruction = (y * 100);
    equipment = (z * 40 * day1);
    }

    int scuba(int x, int y, int base, int instruction)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need scuba instruction?");
    scanf("%d", &y);

    base = (x * 1000);
    instruction = (y * 100);
    }

    int skydive(int x, int y, int z, int base, int lodge, int inn, int day1, int
    day2)
    {


    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people are going to be staying in the Wilderness Lodge?");
    scanf("%d", &y);
    printf("\nHow many people will be staying at the Luxury Inn?");
    scanf("%d", &z);
    printf("\nHow many days?");
    scanf("%d", day1);
    printf("How many days?");
    scanf"%d", day2);
    base = x * 400;
    lodge = (y * 65 * day1);
    inn = (x * 120 * day2);

    }

    int baron(int x, int y, int day1, int base, int equipment)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need to rent equipment?");
    scanf("%d", &y);
    printf("How many days?");
    scanf("%d", &day1);

    base = (x * 700);
    equipment = (y * 40 * day1);

    }

    it still won't work right...it's giving me these errors...
    --------------------Configuration: lab1 - Win32 Debug--------------------
    Compiling...
    lab1.c
    C:\Temp\lab1.c(35) : error C2198: 'devils' : too few actual parameters
    C:\Temp\lab1.c(37) : error C2198: 'scuba' : too few actual parameters
    C:\Temp\lab1.c(39) : error C2198: 'skydive' : too few actual parameters
    C:\Temp\lab1.c(41) : error C2198: 'baron' : too few actual parameters
    C:\Temp\lab1.c(87) : error C2143: syntax error : missing ';' before 'string'
    C:\Temp\lab1.c(87) : warning C4550: expression evaluates to a function which is missing an argument list
    C:\Temp\lab1.c(87) : error C2059: syntax error : ')'
    Error executing cl.exe.

    lab1.obj - 6 error(s), 1 warning(s)

  5. #5
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    C:\Temp\lab1.c(35) : error C2198: 'devils' : too few actual parameters
    C:\Temp\lab1.c(37) : error C2198: 'scuba' : too few actual parameters
    C:\Temp\lab1.c(39) : error C2198: 'skydive' : too few actual parameters
    C:\Temp\lab1.c(41) : error C2198: 'baron' : too few actual parameters
    These are all because when you declared the functions, you wrote them with 5-6 parameters, but when you called them from main, you only passed them three.

  6. #6
    Registered User breed's Avatar
    Join Date
    Oct 2001
    Posts
    91
    just a quick hint on functions

    C:\Temp\lab1.c(35) : error C2198: 'devils' : too few actual parameters

    prototype/* devils(int i, char j, char *str);
    has args of the integer type a
    & a char type also a char type string;


    func call /* devils(6, ch, name);
    when called pass values that need to be processed by the declaration;



    declaration /* devils(int i, char j, char *str);
    here is where the values get processed/manipulated;

    hope i helps
    Before you judge a man, walk a mile in his
    shoes. After that, who cares.. He's a mile away and you've got
    his shoes.
    ************William Connoly

  7. #7
    Unregistered
    Guest
    /*Vincent Irick*/
    /*Lab 1*/
    /*This lab gives the user the choice of 4 different vacations plans. The user
    inputs the
    number of people in the group and also the number of days. The user is then
    given the base amount
    the have to deposit and the amount per person*/

    #include <stdio.h>



    void main()
    {

    int a,b,c,d,e,f, y ,z, count;
    char x;
    int devils(int *x, int *y, int *z, int *day1, int *base, int *equipment, int *instruction, int *total, int *answer, int *count); /*the devils
    function prototype*/
    int scuba(int *x, int *y, int *base, int *instruction, int *total); /*the scuba function prototype*/
    int skydive(int, int, int, int, int, int, int, int, int); /*skydive function
    prototype*/
    int baron(int, int, int, int, int, int); /*baron function prototype*/

    count = 1;
    while (count = 1)
    {
    printf("Hi, Welcome to the High Adventure Agency. Please select a vacation package");
    printf("\n\nDevil's Courthourse Adventure Weekend");
    printf("An action packed three days weekend camping trip in North Carolina");
    printf("\nScuba Bahama");
    printf("\n\n A week-long cruise to Bahama with three days of scuba diving");
    printf("\nThe Sky Dive Colorado");
    printf("\n\n Four thrilling days with expert sky diving instructors in Colorado Springs");
    printf("\nBaron Cliff");
    printf("\n\nEight days spent hiking and exporing caves in the Baron Cliff Wilderness");
    printf("\nPlease select a vacation package by entering the first letter in lowercase: ");
    scanf("%c", &x);
    if (x == 'd')
    devils(int &x, int &y, int &z, int &day1, int &base, int &equipment, int &instruction, int &total, int &answer, int &count);
    if (x == 's');
    scuba(int &x, int &y, int &base, int &instruction, int &total);
    if (x == 't')
    skydive(a,b,c,d,e,f,x, y, z);
    if (x == 'b')
    baron(a,b,c,d,x, y);
    }
    }

    int devils(int &x, int &y, int &z, int &day1, int &base, int &equipment, int
    &instruction, int &total, int &answer, int &count)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need climbing instruction?");
    scanf("%d", &y);
    printf("\nHow many people need to rent equipment?");
    scanf("%d", &z);
    printf("How many days?");
    scanf("%d", &day1);

    base = (x * 350);
    instruction = (y * 100);
    equipment = (z * 40 * day1);
    total = (base + instruction + equipment);

    printf("\n People going on trip: %d", x);
    printf("\n Peope renting equipment: %d", z);
    printf("\n How many days: %d", day1);
    printf("\n Base price: %d", base);
    printf("\n Instruction price: %d", instruction);
    printf("\n Equipment price: %d", equipment);
    printf("\n Total price: %d", total);
    printf("\n Would you like to continue?: ");
    scanf("%c", &answer);
    if(answer == 'y')
    {count = 2;}
    if(answer == 'n')
    {count = 1;}

    }

    int scuba(int x, int y, int base, int instruction, int total)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need scuba instruction?");
    scanf("%d", &y);

    base = (x * 1000);
    instruction = (y * 100);
    total = (base + instruction);

    printf("\n People going on trip: %d", x);
    printf("Base price: %d", base);
    printf("\n Instruction price: %d", instruction);
    printf("\n Total price: %d", total);


    }

    int skydive(int x, int y, int z, int base, int lodge, int inn, int day1, int
    day2, int total)
    {


    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people are going to be staying in the Wilderness Lodge?");
    scanf("%d", &y);
    printf("\nHow many people will be staying at the Luxury Inn?");
    scanf("%d", &z);
    printf("\nHow many days?");
    scanf("%d", day1);
    printf("How many days?");
    scanf("%d", day2);
    base = (x * 400);
    lodge = (y * 65 * day1);
    inn = (x * 120 * day2);
    total = (base + lodge + inn);

    printf("\n People going on trip: %d", x);
    printf("\n Peope staying at the Lodge: %d", y);
    printf("\n Peope staying at the Inn: %d", z);
    printf("\n How many days: %d", day1);
    printf("Base price: %d", base);
    printf("\n Lodge price: %d", lodge);
    printf("\n Inn price: %d", inn);
    printf("\n Total price: %d", total);


    }

    int baron(int x, int y, int day1, int base, int equipment, int total)
    {
    printf("How many people are going on the trip?");
    scanf("%d", &x);
    printf("\nHow many people need to rent equipment?");
    scanf("%d", &y);
    printf("How many days?");
    scanf("%d", &day1);

    base = (x * 700);
    equipment = (y * 40 * day1);
    total = (base + equipment);

    printf("\n People going on trip: %d", x);
    printf("\n Peope renting equipment: %d", equipment);
    printf("\n How many days: %d", day1);
    printf("Base price: %d", base);
    printf("\n Equipment price: %d", equipment);
    printf("\n Total price: %d", total);




    }

    i did what you told me...but this is the error that it gave me....
    -------------------Configuration: lab1 - Win32 Debug--------------------
    Compiling...
    lab1.c
    C:\Documents and Settings\cstlab\Desktop\lab1.c(40) : error C2143: syntax error : missing ')' before 'type'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(40) : error C2198: 'devils' : too few actual parameters
    C:\Documents and Settings\cstlab\Desktop\lab1.c(40) : error C2059: syntax error : ')'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(42) : error C2143: syntax error : missing ')' before 'type'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(42) : error C2198: 'scuba' : too few actual parameters
    C:\Documents and Settings\cstlab\Desktop\lab1.c(42) : error C2059: syntax error : ')'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(50) : error C2143: syntax error : missing ')' before '&'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(50) : error C2143: syntax error : missing '{' before '&'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(50) : error C2059: syntax error : '&'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(51) : error C2059: syntax error : ')'
    C:\Documents and Settings\cstlab\Desktop\lab1.c(84) : warning C4028: formal parameter 1 different from declaration
    C:\Documents and Settings\cstlab\Desktop\lab1.c(84) : warning C4028: formal parameter 2 different from declaration
    C:\Documents and Settings\cstlab\Desktop\lab1.c(84) : warning C4028: formal parameter 3 different from declaration
    C:\Documents and Settings\cstlab\Desktop\lab1.c(84) : warning C4028: formal parameter 4 different from declaration
    C:\Documents and Settings\cstlab\Desktop\lab1.c(84) : warning C4028: formal parameter 5 different from declaration
    Error executing cl.exe.

    lab1.obj - 10 error(s), 5 warning(s)

  8. #8
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You have design problems with your code.....
    look at this function ( the others are the same i just picked this one)
    Code:
    int skydive(int x, int y, int z, int base, int lodge, int inn, int day1, int 
    day2, int total) 
    { 
    
    
    printf("How many people are going on the trip?"); 
    scanf("%d", &x); 
    printf("\nHow many people are going to be staying in the Wilderness Lodge?"); 
    scanf("%d", &y); 
    printf("\nHow many people will be staying at the Luxury Inn?"); 
    scanf("%d", &z); 
    printf("\nHow many days?"); 
    scanf("%d", day1); 
    printf("How many days?"); 
    scanf("%d", day2); 
    base = (x * 400); 
    lodge = (y * 65 * day1); 
    inn = (x * 120 * day2); 
    total = (base + lodge + inn); 
    
    printf("\n People going on trip: %d", x); 
    printf("\n Peope staying at the Lodge: %d", y); 
    printf("\n Peope staying at the Inn: %d", z); 
    printf("\n How many days: %d", day1); 
    printf("Base price: %d", base); 
    printf("\n Lodge price: %d", lodge); 
    printf("\n Inn price: %d", inn); 
    printf("\n Total price: %d", total); 
    }
    For a start you pass in parameters x,y,z,day1 and day2. You then immediately write over whatever you passed in because those variables are used immediately in scanf() statements. That means they do not have to be passed in at all and instead should be local variables to the function. You have done the same thing everywhere. All this does is make your code confusing. Try going through it and reordering the code a little.You will find it much easier to see whats going on then.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  2. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 01:41 PM
  3. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 05:39 AM
  4. Inline functions and inheritance
    By hpy_gilmore8 in forum C++ Programming
    Replies: 3
    Last Post: 01-14-2004, 06:46 PM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 07:53 AM