Thread: Help in c programming

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    1

    Help in c programming

    can you please help in this c programming?
    i am suppose to print the books using string, but wud have to use array, i tried it but its not working, and also for each of the books , an address shud be printed, i tried that using a pointer but is only printing one general address, wud writing the books as string be a form of structure?. here is ma source code
    Code:
    #include <stdio.h>
    #include <conio.h>
    
    
    int discount (int x);
    int tax (int y);
    
    
    main ()
    {
    
    
        int code[10];
       int i,after_discount;
       float after_tax;
       int total;
       int cost=500;
       float date;
    
    
       printf("Enter the date the books were purchased mm.yyyy\t");
       scanf("%f",&date);
    
    
       for (i=0;i<10;i++){
           printf ("Enter the book code:\t ");
          scanf ("%d", &code[i]);
          }
    
    
       total = 500.00 * 10;
       after_discount = total - discount (cost);
       after_tax = after_discount + tax (total);
    
    
       clrscr();
    
    
     printf ("**************************Triple S&T Bookstore****************************\n");
    
    
      printf( "%10s%45s\n", "***BOOKS***", "***CODES***" );
    
    
       printf ("A Painted House\t %35d\n", code [0]);
       printf ("The Firm\t %35d\n", code [1]);
       printf ("The Testament\t %35d\n", code [2]);
       printf ("Pelican Brief\t %35d\n", code [3]);
       printf ("Runaway Jury\t %35d\n", code [4]);
       printf ("Rain Maker\t %35d\n", code [5]);
       printf ("Street Lawyer\t %35d\n", code [6]);
       printf ("A Time to Kill\t %35d\n", code [7]);
       printf ("The Confession\t %35d\n", code [8]);
       printf ("Bleachers\t %35d\n", code [9]);
    
    
    
    
    
    
      printf ("*************************************************************************\n");
    
    
    
    
    
    
       printf ("Discount is:$ %d\n", discount(cost));
       printf ("After discount:$ %d\n",  after_discount);
       printf ("Tax is :$ %d\n", tax (total));
       printf ("Total Amount to be paid:$ %.2f", after_tax);
    
    
    
    
    
    
    getch ();
    return 0;
    }
    
    
    int discount ( int x)
       {
       int four_books,discount;
        four_books = x * 4;
        discount = 0.10*four_books;
        return discount;
        }
    
    
    int tax (int y)
        {
       int tax;
           tax = 0.05 *y;
          return tax;
          }

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    you are posting in the wrong forum - and please dont write in baby language - wud cud shud ma etc
    i am sorry but your code is a bit messy- write small experimental 'test' programs that do what you expect to try out the features you need to use
    use int main()
    dont use turbo c compiler or its outdated headers
    INITIALISE variables

    And consider - if your program has values that are never meant to change then show that - use define statements and CAPITAL letters for the name of that data - its a message to you (and other programmers) that the names in CAPS are constant values like your tax rate - which by the way cannot be an int - though i would like my tax to be calculated like that - 0% or -1% is what i would like to pay for sure
    Last edited by rogster001; 11-06-2012 at 03:21 PM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2012, 01:03 AM
  2. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM