GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Ok, it's been a slow day at work, so I thought I'd exercise my fortran coding skills (or lack thereof!), and see if I could code the process of making a cup of tea. Does anyone else have any other pointless programs? Is there a website dedicated to this sort of thing? Feel free to post any other ones you've written/seen.
To reiterate, work's going really well today!...
Code:
program tea_break
implicit none
integer :: i, bags, mug, biscuit, tea, drink, people
real :: water, sugar, milk, temp, brewtime
open (10, file='recipe.dat')
read (10,*) water, sugar, milk, bags, mug, brewtime, people
close (10)
open (20, file='tea.out')
do i=1, people
if (thirst .gt. 0) then
do temp=1, 100
do while (brewtime .lt. 3)
if (temp .eq. 100) then
tea=(water*bags)
else if (temp .lt. 100) exit
endif
if (milk .gt. 0) then
if (sugar .gt. 0) then
mug=tea+sugar+milk
else
mug=tea+milk
else
if (sugar .gt. 0) then
mug=tea+sugar
else
mug=tea
endif
enddo
enddo
endif
if (biscuit .gt. 0) then
drink=mug+biscuit
write(20,*) drink
else
write(20,*) mug
endif
close (20)
enddo
end program tea_break
It's coded (very badly) in C. You get extra points for optimising this, and the teabreak.h header file is left as an exercise for the reader.
Code:
#include <stdio.h>
#include "teabreak.h"
int main(){
if(Tbreak==1){
findCleanMug();
if(noMug==true){
printf("Error: No Clean Mugs.\nThis program requires =>1 Clean Mug to run.\n");
exit _IN_A_MOOD_;
}
else{
if(beverage=='Tea'){
put(_TEABAG_,_CUP_);
put(_SUGAR_,_CUP_);
put(_WATER_,_CUP_);
put(_MILK_,_CUP_);
exit _HAPPY_;
}
else if(beverage=='Coffee'){
put(_COFFEE_,_CUP_);
put(_SUGAR_,_CUP_);
put(_WATER_,_CUP_);
put(_MILK_,_CUP_);
exit _HAPPY_;
}
else if(beverage=='Decaf'){
printf("Decaf? What good is that?\n");
put(_ESPRESSO_,_CUP_);
put(_SUGAR_,_CUP_);
put(_WATER_,CUP_);
put(_MILK_,_CUP_);
exit _COMPLETELY_WIRED_;
}
else if(beverage=='Alcohol'){
while(stillStanding){
put(_VODKA_,_CUP_);
put(_MORE_VODKA_,_CUP_);
drink(_CUP_);
put(_VODKA_,_CUP_);
put(_MORE_VODKA_,_CUP_);
drink(_CUP_);
}
fallOver();
fallAsleep();
/* This can't happen */
if(awake==1){
exit _WITH_HEADACHE_;
}
}
else{
printf("Error: No beverage selected.\n");
exit _STILL_THIRSTY_;
}
}
}
else{
keepWorking();
exit _IMPATIENT_;
}
/* shouldn't get here... */
exit _CONFUSED_;
}
I left out the error checking due to this being a pre-pre-pre-pre-alpha program. Don't try to run this program without error checking, it could possibly do a fandango on core, which is a Bad Thing.
After 10 glasses I don't mind pretending anything....Why is the ceiling where the floor used to be? wGoooz muvigg the keuss on my Ketbosrd? OOOOOOOh, where's the bucket...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.