Ok, so I grabbed a program in my book and expanded on it to play with some things. It is very basic, just grabs a user input and displays a result. However, I'm kind of happy with this as my first C Program since it only took like 15-20 minutes to understand everything it covers. In this I managed to incorporate loops, constants, importing, user input, output, placeholders in format strings, conditional statements, and arithmetic expressions. Here is the code:
Code:
#include <stdio.h>
#define HEART_BEAT 75
int
main(void)
{
int heart = 0;
int diff = 0;
while(heart>=0)
{
printf("Enter the heartbeat: ");
scanf("%d", &heart);
if(heart<0)
return(0);
if(heart>HEART_BEAT)
{
diff = heart - HEART_BEAT;
if(diff>25)
printf("The heart rate is very high. Rate is %d above recommended heart rate.\n\n",diff);
else
printf("The heart rate is high by %d.\n\n",diff);
}
else if(heart<HEART_BEAT)
{
diff = HEART_BEAT - heart;
if(diff>25)
printf("The heart rate is very low. Rate is %d above recommended heart rate.\n\n",diff);
else
printf("The heart rate is low by %d.\n\n",diff);
}
else
printf("The heart rate is ideal.\n\n");
}
return(0);
}
What are the thoughts on this? I'm getting a grasp of the basic concepts I skimmed through in the first 6 chapters of my book. Any suggestions as far as expanding this more and how, or if I did anything that is stylistically bad?