Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
void display(char, char*, float, int, float);

display(name,item,price,qtty,payment);

void display(char name,char*item,float price,int qtty,float payment)
{
	fflush(stdin);
	printf("\n----------------------------------------------------");
	printf("\n-                RECEIPT OF PURCHASE               -");
	printf("\n----------------------------------------------------");
	printf("\nName        : %s",name);
	printf("\nItem        : %s",item);
	printf("\nPrice       : RM %.2f",price);
	printf("\nQuantity    : %d",qtty);
	printf("\nPayment     : RM %.2f",payment);
	printf("\n----------------------------------------------------");
}


What I have tried:

The display output just only
----------------------------------------------------
                 RECEIPT OF PURCHASE
---------------------------------------------------
Posted
Updated 15-Jan-21 23:05pm
v3

1 solution

When you call printf, you can provide a number of arguments. The first is the format, and it is mandatory - it tells the function what it is to do.
The format string you provide contains characters to print "\nName: " and "type specifiers" which describe the rest of the arguments - these are always a percent character followed by at least one other character, which describes the data.
%c	character
%d	decimal (integer) number (base 10)
%e	exponential floating-point number
%f	floating-point number
%i	integer (base 10)
%o	octal number (base 8)
%s	a string of characters
%u	unsigned decimal (integer) number
%x	number in hexadecimal (base 16)
%%	print a percent sign
You are telling it to print a string:
printf("\nName : %s",name);

But name is defined as a character:
void display(char name, ...

A string requires an address, not a character value!

I'd suspect that you want to pass a char* to your display function, since most people have more that a single character in their names!
 
Share this answer
 
Comments
tan alan 15-Jan-21 14:14pm    
i change the name to the username as variable,but the display display did not come out the print out function
OriginalGriff 15-Jan-21 14:28pm    
And what did you pass? I can't see your code, remember?
tan alan 15-Jan-21 14:40pm    
i change to printf("\nName : %c",name); its display the equal sign symbol what it means ?
OriginalGriff 15-Jan-21 14:52pm    
And what did you pass to the "display" function when you called it?
tan alan 16-Jan-21 0:37am    
same as
void display(char name,char*item,float price,int qtty,float payment)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900