I am receiving this error
markup.c: In function ‘GetPrice’:
markup.c:16:23: error: ‘markup’ undeclared (first use in this function)
markup.c:16:23: note: each undeclared identifier is reported only once for each function it appears in
markup.c:17:1: error: ‘output’ undeclared (first use in this function)

here is my codes

    // File: markup.c



        #include<stdio.h>
        // define the value for constant MARKUP


        #define MARKUP 0.1
        float GetPrice(float finalvalue)
        {
        finalvalue=finalvalue-markup*100;
        output=finalvalue;
        return (float)output;
        }



    int main()
    {
    // declare variables

    char proceed;

    float markupvalue;

    float value;

    float finalvalue; 

    float markup=0.1;
    // ask user if they want to use markup calculator
    printf("Would you like to markup an item? y/n:");
        scanf("%c", &proceed);

        // if yes, proceed to next step
        if(proceed == 'y')
        {

    // ask user what item they want to markup
    printf("please enter item value you would like to markup:");
    scanf("%f", &value);

    // print current of an item
    printf("The value you entered is: %c%.2f\n",'$',value);

    // display current markup rate
    printf("The current markup rate is %.1f%c.\n",markup*100,'%');

    finalvalue=(value-markup*100);
    // final price of an item
    printf("The price for your item after markup is: %c%.2f\n",'$',(float)GetPrice(finalvalue));

    }else
    // display this message if user don't want to use markup calculator
    printf("If you didn't want to markup an item you can leave. \n\n");

    // display end message
     printf("Thank you for using Markup Calculator. \n");
    return 0;
    }

where is markup defined in getprice() ? if you trying to use the macro defined, then it is MARKUP (in capitals) not markup. change it to capitals or define another markup in getprice() as shown:

int markup=9;

or any value which you want. try it and thanks.

Edited 4 Years Ago by nitin1

Take note to what nitin1 said, however, there are other issues.

  1. In your Getprice() function you didn't variable output was not declared. It just came out of the blues. These I did to make it work:

        #define MARKUP 0.1
    
        float GetPrice(float finalvalue)
        {
        finalvalue = finalvalue - MARKUP * 100;  // markup was used
        float output = finalvalue;  // you don't really need output
        return (float)output;
        }
    

But really, I don't know why you need to still have to use another variable, when all you can do it just return the "finalvalue".

  1. In your main() function, the variable "markupvalue" was not also used. Though, your code will complie and run, but you might what to also check that.

Hope this help

Edited 4 Years Ago by 2teez

C is Case Sensitive it means you must use all variables, macros, functions, ets as is in decleration.
You also have to declare all variables before you are using them.
I recommend you to use Camel Notation in naming of everythings except macros.

Edited 4 Years Ago by VatooVatoo

This article has been dead for over six months. Start a new discussion instead.