c++ function error

can anyone plz tell why this function is invalid?
wht shud i do?

1
2
3
4
5
6
7
8
9
10
11
char convertDiscount(char discount)
{
     char discountPercent;

     if(discount == 'N') discountPercent = "0%";
     else if(discount == 'B') discountPercent = "10%";
     else if(discount == 'D') discountPercent = "20%";
     else if(discount == 'T') discountPercent = "30%";
     
     return discountPercent;
}
You are assigning string literal to the char.
sorry. really very novice at c++
cant understand wht did u mean

can u tell at wht line? & wht will be correct answer?
Change your function return type,you are trying to return a string type using a char type
tnx mate works perfect :)
char is a variable that can hold only one character,
but you're assignig to it more then one chracter:
discountPercent = "10%";

"10%" is not of type char, it is string literal, so you need char* (pointer to the string) to assign all the individual characters;
Last edited on
Topic archived. No new replies allowed.