Thread: Basic C Problems

  1. #1
    Registered User
    Join Date
    Jul 2016
    Posts
    2

    Basic C Problems

    Basic C Problems-img_20160727_132718-jpgcan i get a clue for this?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    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.

  3. #3
    Registered User
    Join Date
    Jul 2016
    Posts
    2
    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);
    
    
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,667
    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.

  5. #5
    Registered User
    Join Date
    Jul 2016
    Posts
    6
    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);
    
    
    }

  6. #6
    Registered User
    Join Date
    Jul 2016
    Posts
    6
    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);
    
    
    }

  7. #7
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Please note that you are technically in violation of a forum rule.
    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.
    Please do not keep making new accounts.

    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.

  8. #8
    Registered User
    Join Date
    Jul 2016
    Posts
    6
    i have no idea really
    thank you so much

  9. #9
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Unfortunately it's very common for people to not know or care about the rules in today's society.

  10. #10
    Registered User
    Join Date
    Jul 2016
    Posts
    6
    this will be my last acct for this forum~~
    i lvoe this forum more power!

  11. #11
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    It's probably not the best idea to use scanf to read in strings.
    Read up about fgets().
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. visual basic mod function problems
    By Neo11011 in forum Windows Programming
    Replies: 2
    Last Post: 03-23-2012, 03:01 AM
  2. Problems with a basic program.
    By JOZZY& Wakko in forum C Programming
    Replies: 8
    Last Post: 11-04-2009, 09:08 AM
  3. Basic Program Problems
    By pobri19 in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2008, 12:58 PM
  4. A few problems with basic text graphics...
    By 20,000leeks in forum Game Programming
    Replies: 3
    Last Post: 09-20-2006, 05:01 AM
  5. Problems compiling basic program
    By thestrap in forum C Programming
    Replies: 15
    Last Post: 09-05-2006, 10:41 AM

Tags for this Thread