+ 7

Someone Help me with this code!! (Closed)

/*What I want the code to do is calculate the net-total of all gifts brought and then take the Total as an Input to automatically apply 15 percent discount in it, now algebraically-adding all the gifts work fine but It just shows the discounted total price as 0 why ? (sorry for the bad english) */ #include <stdio.h> int main () { float gift1, gift2, gift3, total, discount; // Defines the Variables to hold. printf("How much do you want to spend on your dad?"); scanf ("%f", &gift1); printf("How much do you want to spend on your mom?"); scanf("%f", &gift2); printf("How much do you want to spend on your brother?"); scanf("%f", &gift3); total = gift1+gift2+gift3; // Calculates the algebraic addition to get the the total value. printf ("\n Total of all that would be %.f", total); scanf("%.f", &total); // Gets the "total" value for input. total = 0.85 * discount; // Getting a 15% discount in total value. printf("\n If you get a discount of 15 percent on that you would still "); printf("have to pay %.f", total); return 0; }

14th Jun 2021, 6:40 PM
Hemang Mitra
Hemang Mitra - avatar
30 ответов
+ 3
https://code.sololearn.com/cdSm8YLfUgmq/?ref=app //Is this your expected output?
14th Jun 2021, 6:46 PM
Atul [Inactive]
+ 2
Hemang Mitra I made some changes in my code please check it again
14th Jun 2021, 7:25 PM
Atul [Inactive]
+ 1
No like, the total price after discount cannot be 0, unless we input all the first three variables as 0
14th Jun 2021, 6:59 PM
Hemang Mitra
Hemang Mitra - avatar
+ 1
we should not need to input fourth value, the "total' variable is taken as the input to apply discount on it.
14th Jun 2021, 7:05 PM
Hemang Mitra
Hemang Mitra - avatar
+ 1
Hemang Mitra if possible please provide an example
14th Jun 2021, 7:06 PM
Atul [Inactive]
+ 1
Hemang Mitra if you do not need to take total as input from user, remove the line 14 from my code ^^
14th Jun 2021, 7:16 PM
visph
visph - avatar
+ 1
Well what I want the code to do is simple, first it will ask for the first three variables labeled as gift1, gidt2 and gift3 after you input the value then it will add cost of all gifts then, again it will automatically take input from that total cost and apply a discount of 15% and then give you the discounted cost.
14th Jun 2021, 7:17 PM
Hemang Mitra
Hemang Mitra - avatar
+ 1
so, you input the total (as fourth value) instead of using the computed total just before... my code works as expected ^^
14th Jun 2021, 7:19 PM
visph
visph - avatar
+ 1
Hemang Mitra just check my code again
14th Jun 2021, 7:19 PM
Atul [Inactive]
+ 1
Visph I tried the same code in other ides and locally in my computer, the compiler are not giving the same output as the one in sololeran how ?
14th Jun 2021, 7:23 PM
Hemang Mitra
Hemang Mitra - avatar
+ 1
Hemang Mitra updated my code to give only 2 decimals...
14th Jun 2021, 7:24 PM
visph
visph - avatar
+ 1
Hemang Mitra corrected first the %.f format wich give int instead of float ^^
14th Jun 2021, 7:26 PM
visph
visph - avatar
+ 1
visph Yes it works thanks for bearing with me lol and thanks
14th Jun 2021, 7:27 PM
Hemang Mitra
Hemang Mitra - avatar
+ 1
Atul It doesn't work but, thanks for the effort.
14th Jun 2021, 7:31 PM
Hemang Mitra
Hemang Mitra - avatar
+ 1
Hemang Mitra sorry I am unable to help you in fully. May be I was unable to get your question. Sorry for thay
14th Jun 2021, 7:37 PM
Atul [Inactive]
+ 1
Atul No problem you gave your all for it.
14th Jun 2021, 7:48 PM
Hemang Mitra
Hemang Mitra - avatar
0
what is the fourth value you expect as input?
14th Jun 2021, 7:00 PM
visph
visph - avatar
0
Change Total=0.85*discount...... To Total=0.85*total
15th Jun 2021, 3:47 PM
Suresh