Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Visual C++, help me!

  • 25-11-2001 06:41PM
    #1
    Registered Users, Registered Users 2 Posts: 2,623 ✭✭✭


    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,623 ✭✭✭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