Saturday, July 15, 2006

Getting My C on

I bought a C book on wednesday night, it on here on friday morning. It's a pretty good book it's called "Absolute beginners Guide to Learning C". It's so Good that by Friday night i wrote my first C Program. What does it do i here you ask?

It works out how much i get paid, and how many hours i work. For any fellow code heads, check it out.


/*Time card Calulator
Jonathan Dalrymple
July 14th, 2006
*/
#include <stdio.h>

/*Declare the varibles for each day*/
float monday, tuesday, wednesday, thursday, friday;
/*Declare the number of days worked*/
float daysInWeek;
/*Rate of pay*/
float rop;
/*New varible to handle the results of our calculations*/
float hoursWorked, payExpected;


main()
{
printf("Welcome to Jon's Payroll program \n");
/*Get info from the user*/
printf("How many hours did you work on Monday? \n");
scanf("%f", & monday);

printf("How many hours did you work on Tuesday? \n");
scanf("%f", & tuesday);

printf("How many hours did you work on Wednesday? \n");
scanf("%f", & wednesday);

printf("How many hours did you work on Thursday? \n");
scanf("%f", & thursday);

printf("How many hours did you work on Friday? \n");
scanf("%f", & friday);

/*Get value to dvide by
printf("How many days did you work this week?");
scanf("%f", & daysInWeek);*/

/*How much was the user getting paid*/
printf("How much were you paid?\n");
scanf("%2f", & rop);

/*Do the math*/
hoursWorked = (monday + tuesday + wednesday + thursday + friday);
payExpected = (hoursWorked * rop);

/*Return the results*/
printf("You worked %2f %s",hoursWorked," Hours \n");
printf("You should get paid £%2f\n", payExpected);

return 0;
}



Really simple, works nicely too, eventually i 'port' it into a palm os app. But for now it's as is.

In the meantime, i'm going to watch the new series of Stargate SG-1, with it's weird babies that grow up in 30 seconds.

No comments: