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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
How do I make a Program the Default Program? fh2level Mac Basics and Help 8 Jun 29, 2006 06:59 PM
What programming languages to use for making games/programs? Mammoth Mac Programming 10 Mar 19, 2006 03:19 AM
What's the best program to make this program? hotwire132002 Mac Programming 5 Jul 27, 2005 11:25 PM
C Programming - What Program ? .Joel Mac Applications and Mac App Store 3 May 11, 2005 06:10 AM
Mac programs vs. Windows programs GrannySmith_G5 Mac Applications and Mac App Store 10 Sep 4, 2003 11:50 AM


All times are GMT -5. The time now is 08:47 PM.

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

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