Thread: Please help a n00b - several issues with my program

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    1

    Please help a n00b - several issues with my program

    PLEASE HELP ASAP!! I have only been learning C for about a month so I am not as familiar with the terms and concepts as I would like to be. I know that there are actually more issues than I have mentioned; particularly with my assignment operators. I know I need to have some variables with asterisks in my function prototypes and calls but I am not sure when, where and why to use the asterisk and ampersand in functions.

    This program is supposed to help a bookstore estimate its business.
    I am required to: 1. Use a defined constant for the rate of profit.
    2. Input should not be case-sensitive, so I have used a tolower() function. If the input is erroneous I am supposed to use an exit() function, which I am not sure I have done correctly.
    3. Function to calculate # of books to be ordered, function to calculate profit, and function to output everything.

    The things I need help with are:
    1. Something is wrong with my logic statements for whether the book is suggested, required, new or old and I am unsure of what it is.

    2. How do I use the exit functions correctly so that if someone enters 'Q' when it asks for 'R' or 'S' the program aborts?

    3. I get a warning on line 70: "Passing argument 1 of 'profit' makes integer from pointer without a cast". I have very little understanding of what this means and absolutely no idea how to fix it.

    4a. What am I supposed to put for the return parameter for my 'output' function? It is supposed to output three print statements.
    4b. When calling output() in main, what am I supposed to put inside the parentheses?

    Thanks in advance!!!

    -LowKey Variation in Production

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #define STORE_PROFIT .2
    
    //Function Prototypes
    int books(double, char, char);
    float profit(int, float);
    void output(int num);
    
    int main(void)
    {
    //Declare Variables
        //ISBN
            char i1;
            char i2;
            char i3;
            char i4;
            char i5;
            char i6;
            char i7;
            char i8;
            char i9;
            char i10;
        //Text Code
            char rs;    //Required or Suggested
            char r;     //Required
            char s;     //Suggested
            char no;    //New or Old
            char n;     //New
            char o;     //Old
        //Other
            double lp;   //List Price
            double ee;   //Expected Enrollment
    
    //Input
        printf("Enter ISBN number: ");
        scanf(" %c %c %c %c %c %c %c %c %c %c", &i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8, &i9, &i10);
        printf("Enter price per copy: ");
        scanf(" %lf", &lp);
        printf("Enter expected class enrollment: ");
        scanf(" %lf", &ee);
        printf("Enter 'R' if required or 'S' if suggested: ");
        scanf(" %c", &rs);
        rs = tolower(rs);
        if (rs = r)
            r = rs;
            else if (rs = s)
                    s = rs;
            else exit(0);
        printf("Enter 'N' if new or 'O' if not a new text: ");
        scanf(" %c", &no);
        no = tolower(no);
        if (no = n)
            n = no;
            else if (no = o)
                    o = no;
            else exit(0);
    
    //Compute
    books (ee, rs, no);
    profit (books, STORE_PROFIT);
    
    //Output
    output (0);
    
    
        return 0;
    }//main---------------------------------------------------------------------------------------------------------------------
    
    
    
    
    //Number of Books Function
    int books(double expect, char rs, char no)
    {
    //Pre:  Expected Enrollment and whether r/s and n/o
    //Post: Books needed
    
    //Local Declarations
            char r;     //Required
            char s;     //Suggested
            char n;     //New
            char o;     //Old
            int ex;   //Expected Enrollment
            int need; //Books needed
    
    //Logic Statements
        if (rs = r)
            if (no = n)
                need = .9 * ex;
            else if (no = o)
                need = .65 * ex;
    
        else if (rs = s)
            if (no = n)
                need = .4 * ex;
            else if (no = o)
                need = .2 * ex;
    
    
    return need;
    }//number of books function-------------------------------------------------------------------------------------------------
    
    
    
    
    //Calculate Profit Function
    float profit(int needed, float stoprof)
    {
    //Pre:  List price & Copies needed
    //Post: Bookstore's profit
    
    //Local Declarations
        float prof; //Profit
        float sdlp; //Store discount off list price
        int need;   //Books needed
    
    //Compute
        prof = sdlp * need;
    
    
    
    return prof;
    }//profit function-----------------------------------------------------------------------------------------------------------
    
    
    
    //Output Function
    void output(int num)
    {
    //Pre: Data
    //Post: Output ISBN, copies needed and profit
    
    //Local Declarations
            char i1;
            char i2;
            char i3;
            char i4;
            char i5;
            char i6;
            char i7;
            char i8;
            char i9;
            char i10;
            int need;
            float prof;
    
    
    printf("\n\nISBN: %c-%c%c-%c%c%c%c%c%c-%c", i1, i2, i3, i4, i5, i6, i7, i8, i9, i10);
    printf("Copies Needed: %d", need);
    printf("Profit: $6.2f", prof);
    
    
    }//output function-----------------------------------------------------------------------------------------------------------

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    3) Try one of the following:

    Code:
    books_needed = books(ee, rs, no);
    profit (books_needed, STORE_PROFIT);
    /*OR*/
    profit ( books(ee, rs, no), STORE_PROFIT);
    books(ee, rs, no) is an integer equal to the return value of the function. books with no parantheses gives you the memory location the function is stored at.


    4a) "output" is a void function, which means it doesn't return anything. Such functions are ended with a "return;". You seem to be confusing the screen output from the printf statements for the return value; they're not the same thing.
    Code:
    while(!asleep) {
       sheep++;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. N00b with n00b question (probably a quick one)
    By jester-race in forum C++ Programming
    Replies: 8
    Last Post: 11-05-2011, 07:01 PM
  2. n00b needs help with small program
    By rightbrainer in forum C Programming
    Replies: 3
    Last Post: 04-15-2009, 05:52 PM
  3. issues with program need help
    By clipsit in forum C Programming
    Replies: 6
    Last Post: 04-03-2008, 09:24 AM
  4. Complete n00b Question, Client -> Sever MMO Program?
    By Zeusbwr in forum Networking/Device Communication
    Replies: 4
    Last Post: 07-28-2005, 08:33 PM
  5. Replies: 8
    Last Post: 03-26-2002, 07:55 AM