Someone Help me with this code!! (Closed) | Sololearn: Learn to code for FREE!

+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; }

c

6/14/2021 6:40:34 PM

Hemang Mitra

30 Answers

New Answer

+2

Hemang Mitra https://code.sololearn.com/cI98cvb7Z0ns/?ref=app

+3

https://code.sololearn.com/cdSm8YLfUgmq/?ref=app //Is this your expected output?

+2

Hemang Mitra I made some changes in my code please check it again

+1

No like, the total price after discount cannot be 0, unless we input all the first three variables as 0

+1

we should not need to input fourth value, the "total' variable is taken as the input to apply discount on it.

+1

Hemang Mitra if possible please provide an example

+1

Hemang Mitra if you do not need to take total as input from user, remove the line 14 from my code ^^

+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.

+1

so, you input the total (as fourth value) instead of using the computed total just before... my code works as expected ^^

+1

Hemang Mitra just check my code again

+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 ?

+1

Hemang Mitra updated my code to give only 2 decimals...

+1

Hemang Mitra corrected first the %.f format wich give int instead of float ^^

+1

visph Yes it works thanks for bearing with me lol and thanks

+1

Atul It doesn't work but, thanks for the effort.

+1

Hemang Mitra sorry I am unable to help you in fully. May be I was unable to get your question. Sorry for thay

+1

Atul No problem you gave your all for it.

0

what is the fourth value you expect as input?

0

Change Total=0.85*discount...... To Total=0.85*total

0

Sanju Subhash Haldar https://www.sololearn.com/discuss/1316935/?ref=app