can i get a clue for this?
can i get a clue for this?
Yes, you read this -> http://cboard.cprogramming.com/c-pro...uncements.html
Then you post an effort.
At least you should be able to manage a printf statement or two.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
im an absolute beginner
god help me ((
Code:#include <stdio.h> #include <conio.h> #include <math.h> int main() { float v1,v2,v3,v4,v5; char 'v1','v2','v3','v4','v5'; float amt,total_amount; printf("Enter Name Of Viand1: "); scanf("%c",&'v1'); printf("\nEnter Price Of Viand1: "); scanf("%f",&v1); printf("Enter Name Of Viand2: "); scanf("%f",&v2); printf("\nEnter Price Of Viand2: "); scanf("%f",&v2); printf("Enter Name Of Viand3: "); scanf("%f",&v3); printf("\nEnter Price Of Viand3: "); scanf("%f",&v3); printf("Enter Name Of Viand4: "); scanf("%f",&v4); printf("\nEnter Price Of Viand4: "); scanf("%f",&v4); printf("Enter Name Of Viand5: "); scanf("%f",&v5); printf("\nEnter Price Of Viand5: "); scanf("%f",&v5); total_amount = (v1+v2+v3+v4+v5*0.12); printf("Total Amount To Be Paid Is:%.3f ",total_amount); printf("Please Enter Amount To Be Paid: "); scanf("%f",&amt); total_amount = total_amount - amt; printf("Change Is:%.3f",total_amount); }
For a first effort, it's not that bad.
> char 'v1','v2','v3','v4','v5';
Variable declarations are not in quotes.
Nor can you name variables with a different type, but the same name.
In C, to store a string, you need an array.
With these things in mind, you might declare
char n1[20],n2[20];
> scanf("%c",&'v1');
To read a string, use the %s format, say
scanf("%s",n1);
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
its me my new acct
this is what i have
seems working rihgt now
Code:#include <stdio.h> #include <conio.h> #include <math.h> int main() { float v1,v2,v3,v4,v5; char n1[10],n2[10],n3[10],n4[10],n5[10]; float amt,total_amount; printf("Enter Name Of Viand1: "); scanf("%s",n1); printf("\nEnter Price Of Viand1: "); scanf("%f",&v1); printf("Enter Name Of Viand2: "); scanf("%s",n2); printf("\nEnter Price Of Viand2: "); scanf("%f",&v2); printf("Enter Name Of Viand3: "); scanf("%s",n3); printf("\nEnter Price Of Viand3: "); scanf("%f",&v3); printf("Enter Name Of Viand4: "); scanf("%s",n4); printf("\nEnter Price Of Viand4: "); scanf("%f",&v4); printf("Enter Name Of Viand5: "); scanf("%s",n5); printf("\nEnter Price Of Viand5: "); scanf("%f",&v5); total_amount = (v1+v2+v3+v4+v5*0.12); printf("\nTotal Amount To Be Paid Is:%.3f ",total_amount); printf("\nPlease Enter Amount To Be Paid: "); scanf("%f",&amt); amt = amt - total_amount; printf("Change Is:%.3f",amt); }
i have a problem with the tax
tax = 90
total must be 844
the total of this code is 1499
idk what is the problem pls help
Code:#include <stdio.h> #include <conio.h> #include <math.h> int main() { float v1,v2,v3,v4,v5; char n1[10],n2[10],n3[10],n4[10],n5[10]; float amt,total_amount,tax; printf("Enter Name Of Viand1: "); scanf("%s",n1); printf("\nEnter Price Of Viand1: "); scanf("%f",&v1); printf("Enter Name Of Viand2: "); scanf("%s",n2); printf("\nEnter Price Of Viand2: "); scanf("%f",&v2); printf("Enter Name Of Viand3: "); scanf("%s",n3); printf("\nEnter Price Of Viand3: "); scanf("%f",&v3); printf("Enter Name Of Viand4: "); scanf("%s",n4); printf("\nEnter Price Of Viand4: "); scanf("%f",&v4); printf("Enter Name Of Viand5: "); scanf("%s",n5); printf("\nEnter Price Of Viand5: "); scanf("%f",&v5); total_amount = (v1+v2+v3+v4+v5); tax = (v1+v2+v3+v4+v5*0.12+total_amount); printf("\nTotal Amount To Be Paid Is:%.3f ",tax); printf("\nPlease Enter Amount To Be Paid: "); scanf("%f",&amt); amt = amt - tax; printf("Change Is:%.3f",amt); }
Please note that you are technically in violation of a forum rule.
Please do not keep making new accounts.9. Users are allowed only one account unless they are given special permission to hold multiple accounts. Users may not share their account or password with others.
total_amount = (v1+v2+v3+v4+v5);
tax = (v1+v2+v3+v4+v5*0.12+total_amount)
I think this works out to v5 * 0.12 being computed first and then all the other stuff is added up.
I would do this instead:
total_amount = v1 + v2 + v3 + v4 + v5;
tax = total_amount * 0.12;
total_amount += tax;
Now total amount is everything added up, plus tax. Tax is just the amount of tax that should be paid.
i have no idea really
thank you so much
Unfortunately it's very common for people to not know or care about the rules in today's society.
this will be my last acct for this forum~~
i lvoe this forum more power!
It's probably not the best idea to use scanf to read in strings.
Read up about fgets().
Double Helix STL