FUNCTIONS
the question is as follows: write a function, ComputeAmount, that takes as input the quantity of an item and the item unit price, and returns the net amount to be paid by customer.

my program is working correctly please advise me what i did wrong here are the codes:

#include<stdio.h>
#include<stdlib.h>
int ComputeAmount(int x, int y);
int main()
{
    int q, amt;


    printf("Enter quatity: ");
    scanf("%d", &q);
    printf("Enter amount: ");
    scanf("%d", &amt);

    system("pause");
    return 1;
}
int ComputeAmount(int x, int y)
{
    int amt, q;
    float netAmount;
    if(amt<=100){
        netAmount=q*amt;
        return("%.2f", netAmount);
        }
        else
        if(amt<=200){
            netAmount=q*(amt*(5/100));
            return("%.2f", netAmount);

        }
        else
        if(amt<=300){
            netAmount=q*(amt*(7.5/100));
            return("%.2f", netAmount);
        }
        if(amt>300){
            netAmount=q*(amt*(15/100));
            return("%.2f", netAmount);
        }
        else
        printf("wrong purchase\n");
    }

Edited 3 Years Ago by nitish.mohiputlall: code was wrong

Comments
We know you're asking about the C language. Use more informative thread titles.

return statements do not have a format such as "%f" -- just simply supply the name of the variable to be return. Example: return netAmount;

Line 21, if(amt<=100){ is testing an uninitialized variable for a specific range. What value it (amt) contains is indeterminate - just whatever was in that stack memory location when the function was called. You need to rework the ComputeAmount() function.

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