-
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]
-
[/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();
}
-
Ok thanks ill have a look in to them and ......SORRY!