ccc chaplja <3

So last week we got a task from our lecturer to make a small program in c giving you how many hours, seconds & minuts coming out of a decided amount of seconds.

"#include <stdio.h>

int main(void) {

int Hora,Miner,Secundus,Plaga;

printf("Penetro amplitudo of secundus: ");
scanf("%d", &Secundus);





Hora = Secundus/3600;
Plaga = Secundus%3600;
Miner = Plaga/60;
Plaga = Plaga%60;
Secundus = Plaga;

printf("Hora: %d Miner: %d Secundus: %d\n", Hora,Miner,Secundus);

return 0;
}
"

After he saw that I've made it in latin he asked me to make it a bit more special.
He want's me to make a similar program just this time when writing a special amount of seconds it only has to write the correct variables used, if you know what I mean.

Like 60 secs is printed ONLY as "1 min" or in this case "0 Mine" instead of "1 Hora, 1 Miner 0 Secundus"

I mean it has to remove the plural form of the variables and the not used variables.

Messy I know, someone got a idea? I would really hate starting using 1000000000000000 elseif commands...

Seems like chaplja is still the king.

Simple is simple

#include <stdio.h>

int main(void) {

int Hora,Miner,Secundus,Plaga;

printf("Penetro amplitudo of secundus: ");
scanf("%d", &Secundus);





Hora = Secundus/3600;
Plaga = Secundus%3600;
Miner = Plaga/60;
Plaga = Plaga%60;
Secundus = Plaga;

if (Hora) printf("%d %s ", Hora, Hora == 1 ? "time" : "timer");
if (Miner) printf("%d %s ", Miner, Miner == 1 ? "minut" : "minutter");
if (Secundus) printf("%d %s", Secundus, Secundus == 1 ? "sekund" : "sekunder");
printf("\n");

return 0;
}
Comments
15
first of all, u shud use clrscr so when you do alt f5 it wont look messy, and I will pm you later on IRC if i can remember how to do it, we had similar task @ school last year.

but why dont you use elseif, just copypaste and edit the code a bit. wont take long
Already did it, but would really love to check your one aswell, just to see how it works with you. Still having some problems.

arovca10 at student.aau.dk

Can you send it there? :(
Parent
The bad thing is, I dont have any of the codes on my computer, as I only do those tasks at school. I have programming nex ton friday, if u still need I can check.
Parent
elseif only, as it seems :p
elseif, just few more lines
"
if (timer > 1 && minutter > 1 && sekunder > 1){
printf("%d timer %d minutter %d sekunder", timer, minutter, sekunder);
} else if (timer > 1 && minutter == 1 && sekunder > 1){
printf("%d timer %d minut %d sekunder", timer, minutter, sekunder);
} else if (timer > 1 && minutter > 1 && sekunder == 1){
printf("%d timer %d minutter %d sekundt", timer, minutter, sekunder);
} else if (timer > 1 && minutter > 1 && sekunder == 1){
printf("%d timer %d minutter %d sekundt", timer, minutter, sekunder);
} else if (timer > 1 && minutter > 1 && sekunder < 1){
printf("%d timer %d minutter", timer, minutter);
} else if (timer > 1 && minutter == 1 && sekunder < 1){
printf("%d timer %d minut", timer, minutter);
} else if (timer == 1 && minutter == 1 && sekunder == 1){
printf("%d time %d minut %d sekund", timer, minutter, sekunder);
} else if (timer == 1 && minutter == 1 && sekunder > 1){
printf("%d time %d minut %d sekunder", timer, minutter, sekunder);
} else if (timer == 1 && minutter > 1 && sekunder == 1){
printf("%d time %d minutter %d sekundt", timer, minutter, sekunder);
} else if (timer == 1 && minutter > 1 && sekunder > 1){
printf("%d time %d minutter %d sekunder", timer, minutter, sekunder);
} else if (timer < 1 && minutter > 1 && sekunder > 1) {
printf(" %d minutter %d sekunder", minutter, sekunder);
} else if (timer < 1 && minutter == 1 && sekunder > 1) {
printf(" %d minut %d sekunder", minutter, sekunder);
} else if (timer < 1 && minutter == 1 && sekunder == 1) {
printf(" %d minut %d sekundt", minutter, sekunder);
} else if (timer < 1 && minutter > 1 && sekunder == 1) {
printf(" %d minutter %d sekundt", minutter, sekunder);
} else if (timer < 1 && minutter == 1 && sekunder == 1) {
printf(" %d minut %d sekundt", minutter, sekunder);
} else if (timer < 1 && minutter < 1 && sekunder > 1) {
printf("%d sekunder", sekunder);
} else if (timer < 1 && minutter < 1 && sekunder == 1) {
printf("%d sekundt", sekunder);
} else if (timer > 1 && minutter < 1 && sekunder > 1) {
printf(" %d timer %d sekunder", timer, sekunder);
} else if (timer > 1 && minutter == 1 && sekunder == 1) {
printf(" %d timer %d minut %d sekundt", timer, minutter, sekunder);
} else if (timer == 1 && minutter < 1 && sekunder == 1) {
printf(" %d time %d sekundt", timer, sekunder);
} else if (timer > 1 && minutter < 1 && sekunder < 1) {
printf("%d timer", timer);
} else if (timer == 1 && minutter == 1 && sekunder < 1) {
printf("%d time %d minut", timer, minutter);
} else if (timer == 1 && minutter > 1 && sekunder < 1) {
printf("%d time %d minutter", timer, minutter);
} else if (timer == 1 && minutter < 1 && sekunder < 1) {
printf("%d time", timer);
} else if (timer < 1 && minutter > 1 && sekunder < 1) {
printf("%d minutter", minutter);
} else if (timer < 1 && minutter == 1 && sekunder < 1) {
printf("%d minut", minutter);
}




return 0;
"

This is danish this time, but isn't there a way to shorten it up! or some other commands doing the trick aswell?
Parent
yeah,as I said, just few more lines :D
no,actually I was never doing anything in C, tho..I would do it a bit differently. instead of putting "Hora" or "Hores" (no latin user) into printf, I would put there any variable, which would be "Hora" or "Hores" depending on wether it is singular or plural, therefore you would save many lines. hope you got my point
Parent
wtf? that are a way too many if-statements
Parent
i guess you could write a method that parses the int's in sequence and determines whether it should suffix s on the end of the word if input > 1 and youd only have to pass your time to the method. of course then you want to do concatenation and stuff so its not really any less coding, but might be closer to an OO design

e: doing it in english that is ;D
yup very smart, just make a method returning String with an Integer as parameter, returns either "" or "s" depending if integer is different from 1 or not. Then concat the method result with the time print.

But looking at what he's writing and asking I think he's a beginner and doesnt know methods or concatenation yet
Parent
yeah, cuz "-s" makes plural in latin.

oh wait?
Parent
considering that doing it in latin got him told to do it again i assumed he would drop that certain aspect
Parent
made it in english now, hate being creative from today.
Parent
i believe theres a word in latin for it but i dont want to get picked on for being a smart arse
Parent
actually the lecturer corrected my latin instead of correcting my work :O

now he's a smart arse!
Parent
Back to top