Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Visual C++, help me!

  • 25-11-2001 5:41pm
    #1
    Registered Users, Registered Users 2 Posts: 2,621 ✭✭✭


    This program is killing me.
    I havnt been attending class as often as i should be, as the code will show, im sure.
    The program is supposed to:
    Take in the list length,take in the prices, list the prices and,
    use the recursive statement to find the lowest price entered.
    *ugh*
    And not done yet is, show the highest price,average price, and allocate the shopper 10 points per ten pounds spent.

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

    int i;
    int num;
    double price[50];
    double rmin;

    void main()
    {
    printf("Welcome to the Shopping list generator.\n");
    printf("How many prices do you want to enter?:");
    scanf("%i", &num);

    for (i=0; i<num; i++)
    {
    printf("Enter a price:");
    scanf("%lf", &price);
    }

    for (i=1; i<=num; i++)
    {
    printf("Item %i: %lf\n", i,price);
    }

    double rmin(double price[], int low, int high)
    {
    static double small = price[0];
    if (price [low] < small)
    {
    small = price[low];
    }
    if (low==high)
    {
    return small;
    }
    else
    return rmin(price, low+1, high);
    }
    printf("The Minimum price was: %lf", rmin);
    }

    I keep getting "error C2599: 'rmin' : local functions are not supported"

    Please help me!


Comments

  • Registered Users, Registered Users 2 Posts: 1,562 ✭✭✭Snaga


    Edited as I missed what you were doing.

    You are trying to have a function inside your main function. This is bold and will not work. I think a quick look at the C book might help.

    I have no compiler on this machine and havent programmed in C for a while so the below probly needs some work :)

    Specify your rminfunc function at the top...i.e. not inside your main()

    i.e.

    #include <whatever.h>

    (try to not name functions the same as variables for ease of coding)

    double rminfunc(double price[], int low, int high){

    blah code blah
    return blah;
    }

    void main(){

    //Instantiate your variables HERE, not outside a function.
    int i;
    int num;
    double price[50];
    double rmin;

    //Your inputting code goes here.

    //Call your function, Youll need to have 'low' and 'high' variables too.
    rmin = rminfunc(price, low, high);

    printf ("low value = %lf", rmin);
    }


    There are some other problems in your code that need fixing but ill leave them for you to figure out. But the basic form of the program should be like the example.


  • Registered Users, Registered Users 2 Posts: 2,621 ✭✭✭Panda


    The project still aint done and its supposed to be in before 10 tomorrow.
    I've brought all this on myself. :D i mean :(

    Still tho, thanks for the pointers there Snaga, it helped.
    Much appreciated.


Advertisement