Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 31, 2004, 09:18 AM   #1
atif.muhammad
Registered User
 
Join Date: Oct 2004
Location: none of your business
Send a message via AIM to atif.muhammad Send a message via MSN to atif.muhammad Send a message via Yahoo to atif.muhammad
C Programming

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*/
atif.muhammad is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Mac programming should be more like iOS programming. moonman239 Mac Programming 13 Feb 17, 2014 01:37 PM
Help with C programming. Meitou Mac Programming 2 Sep 21, 2012 01:36 PM
C++ programming jmfel1926 Mac Programming 4 Sep 14, 2012 07:21 PM

Forum Jump

All times are GMT -5. The time now is 11:08 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC