Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

atif.muhammad

macrumors member
Original poster
Oct 26, 2004
92
0
none of your business
hi,
i've just started learning C and am currently just playing around with its features
however, the compiler says theres a problem with one of my programs. i've got the source code below, could anyone please compile it and tell me whats wrong. dont get pissed off with the program coz im just learning it. also could you tell me some improvements that could be made



/** Simple program which asks for 3 inputs and outputs 5 different answers.
* inputs are integers: a,b,c
* outputs are integers: sum,minus,multiply,divide,remainder*/
#include <stdio.h> /*declare directive*/

main()/*start execution of program*/

{

int a,b,c,sum,minus,multiply,divide,remainder;

printf("Enter the first digit:\n");
scanf("%d", &a);
if (a < 0) /* the first input, a, if negative, outputs a printf statement*/
printf("The value is negative\n\n");
else
printf("The value is positive\n\n");

printf("Enter the second digit:\n");
scanf("%d", &b);
if (b==5) /*if the second input, b, if equals to five outputs a printf statement*/
printf("The value is %d\n", b);

else /**however, if the second input, b, is not equal to 5, then the user is told that the value
*has to be 5 and they must reenter the second input, b*/
do
{
printf("The value has to be 5, not %d\n",b);
printf("Enter the second digit:\n");
scanf("%d", &b);
}

printf("Enter the third digit:\n");
scanf("%d", &c);
if (c < 0) /*this is the same as the first input,a*/
printf("The value is negative\n\n");
else
printf("The value is positive\n\n");

sum = a+b+c; /*add the three inputs*/
printf("The sum of %d + %d + %d is %d\n", a,b,c,sum); /*output the sum of 3 inputs*/

minus = a-b-c; /*minus the three inputs*/
printf("Minus %d and %d from %d and you get %d\n",c,b,a,minus); /*output the minus of 3 inputs*/

multiply = a*b*c; /*multiply the 3 inputs*/
printf("By multiplying %d, %d, %d together, you get %d\n", a,b,c,multiply); /* output the multiplication of 3 inputs*/

divide = c/b; /*divide the third input by the second*/
remainder=c%b; /*find the remainder by the division of 3rd input by 2nd input*/
printf("By dividing %d by %d, you get %d and your remainder is %d\n",c,b,divide,remainder); /*output the remainder and division of third input by second input*/


return 0; /*return*/

}/*end*/
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.