Hi All,
I am a complete Noob to C, this being my first day of what i hope will be a long,wonderful adventure .
I have come up with a very simple program, that just asks some very basic questions of the user and then goes down different interaction tracks based on said user input.
My question is, can someone give me some pointers on best practice - I would prefer a seasoned veteran to give me a going over at this early stage and point me in the right direction so that i don't bed in with any bad habits.
Anyones time on this would be greatly appreciated by myself :
Code:
#include <stdio.h>
int main(void)
{
int numneed,income,outgoing;
char shallwe,fname[30];
fputs("Whats your name ?\n",stdout);
fflush(stdout);
fgets(fname,sizeof(fname),stdin);
printf("Nice to meet you %s\n",fname);
printf("Hi, How much do you need this month to afford a new macbook (£)? : \n" );
scanf("%d", &numneed);
getchar();
if ( numneed > 1500)
printf("WOW That is a lot of cash needed ! \n");
else
printf("Its alot, but might be 'do able' \n");
printf("Well, let's work it out now shall we ? Y or N ? \n");
scanf("%s",&shallwe);
getchar();
if (shallwe == 'y')
{printf("Ok, i will jot down a few figures and we can go from their! \n");
printf("How much will you earn this month (£) ?\n");
scanf( "%d",&income);
printf("Not bad, but what about outgoings ? \n");
scanf( "%d",&outgoing);
int left = income - outgoing;
if ( left >= 0)
printf("Well you do have %d left over, so its not too bad! \n" ,left);
elseprintf("Not good, your in the red! \n");}
elseprintf("Ok well good luck !");
return 0;
}
Kind Regards,
Dan