-1

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 by nitish.mohiputlall: code was wrong

Votes + Comments
We know you're asking about the C language. Use more informative thread titles.
3
Contributors
2
Replies
36
Views
4 Years
Discussion Span
Last Post by rubberman
0

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

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.