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

+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

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

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

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

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

0

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

0

Your mistake in the code was that discount was not assigned with value. And you were doing product of 0.85 and discount to get total.Thus you got 0 as output.Actually no need of discount variable. Well, Good qn bro.👍 I'll post my soln code soon.🙂 https://code.sololearn.com/cS4SXy7p2uYj/?ref=app

0

SREEHARI A H Haha yes I later changed that too. delete the line 14 to get not take input in between. As told by vishp then discount= 0.85 * total; printf("\n If you get a discount of 15 percent on that you would still") printf("have to pay %.2f", discount); return 0;

0

actually you mean to take 85% of total to print as 15% is discount ... then discount = total * 0.15; total= total - discount; printf("%f",total); this is the meaning I get from your question🙂

0

Chinmay Anand Yes, it's right Just remove the line 14 from it, I realized that's the problem scanf, It isn't getting the "total" value for input automatically but rather asking us for the input. So after we give the input for 3 variables it will then ask for us to input the "total" and then discount that, not the total it got by adding all the three variables. Note:- This problems is for only those compiling in standalone multipass compilers(locally in their system mostly) , and sololearn doesn't have the same problem, Because it takes the Inputs first so if we input four variables instead of three it will add the first three then discount the fourth one giving us wrong output in the end. Try it

-1

You may also print the discount amount.😄

-1

https://code.sololearn.com/ca94a12A8a17 #include <stdio.h> int main () { float gift1, gift2, gift3, total, discount=15; // 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 = total- (total * discount)/100; // 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; }