Thread: very Long!

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    2

    very Long!

    HI,
    im quite new to c++ programming i have made this simple programme which adds sales figures entered togther to give you a total.

    But it seems very long and i was woundering how to i cut it down and also next i would like them to be able to be sorted in order of highest to lowest??? any ideas how i go about this???

    Heres the code so far: ........Thanks

    [code] #include <stdio.h>
    #include <conio.h>

    /* This C program produces a */

    void main(void)
    {

    clrscr();


    int a, b, c, d, e, f, g, h;
    clrscr();
    printf("Sales figures For Westwing\n");

    printf("Enter the first branch sales figures :","i");
    scanf("%d", &a);
    printf("Enter the second branch sales figures:");
    scanf("%d", &b);
    printf("Enter the third branch sales figures:");
    scanf("%d", &c);
    printf("Enter the forth branch sales figures:");
    scanf("%d", &d);
    printf("Enter the fith branch sales figures:") ;
    scanf("%d", &e);
    printf("Enter the sixth branch sales figures:");
    scanf("%d", &f);
    printf("Enter the seventh branch sales figures:");
    scanf("%d", &g);
    printf("Enter the eighth branch sales figures:");
    scanf("%d", &h);




    h = a + b + c + d + e + f + g;
    printf("The total amount made for all 8 branches is = %d\n",h);

    getchar();
    getchar(); [/cpde]

  2. #2
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    [/cpde] should be [/code].

    <conio.h> is not a standard header.

    void main(void)....see this link.

    >> But it seems very long and i was woundering how to i cut it down and also next i would like them to be able to be

    Use an array and a loop.

    Code:
    #include <stdio.h>
    
    int main()
    {
        int sales[8];
        int c ;
        int sum = 0 ;
        
        for( c=0; c<8; c++ )
        {
            printf("Enter the Branch No. %d's sales figure :", c+1 ) ;
            scanf( "%d", &sales[c] ) ;
        }
    
        for( c=0; c<8; c++ )
            sum += sales[c] ;     
    
        printf("The total amount made for all 8 branches is = %d\n",sum);
        
        getchar();
        getchar(); 
    }
    Last edited by Dante Shamest; 12-07-2003 at 11:54 AM.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    2
    Ok thanks ill have a look in to them and ......SORRY!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 09-30-2008, 02:12 AM
  2. Having Buffer Problems With Overlapped I/O --
    By Sargera in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 04:46 PM
  3. Problem in Converting Unsigned long to String
    By cprogrammer_18 in forum C Programming
    Replies: 8
    Last Post: 01-14-2006, 08:57 AM
  4. Merge and Heap..which is really faster
    By silicon in forum C++ Programming
    Replies: 2
    Last Post: 05-10-2005, 04:06 PM
  5. Insertion Sort Problem
    By silicon in forum C++ Programming
    Replies: 1
    Last Post: 05-08-2005, 12:30 PM