c++ simpel code....help please =P

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8082
Joined: 27 Aug 2005, 16:00
16
Contact:

c++ simpel code....help please =P

Post by ayu »

I can't get this code to work, it is suposed to count seconds when i insert hours minutes and seconds :/ ....but it only gives me the seconds....what have i missed?






#include<iostream.h>

void skrivtotantsek(int anttimmar, int antminuter, int antsekunder);
void main()
{
int min,tim,sek;

cout<<"Ange timmar: ";
cin>>tim;
cout<<"Ange minuter: ";
cin>>min;
cout<<"Ange sekunder: ";
cin>>sek;
skrivtotantsek(tim,min,sek);

}

void skrivtotantsek(int anttimmar, int antminuter, int antsekunder)

{
int totantsek;
totantsek = (anttimmar/60/60)+(antminuter/60)+antsekunder;
cout<<"Detta ger totalt "<<totantsek<<" sekunder"<<endl;
}
"The best place to hide a tree, is in a forest"

pseudo_opcode
cyber messiah
cyber messiah
Posts: 1201
Joined: 30 Apr 2006, 16:00
15
Location: 127.0.0.1

Post by pseudo_opcode »

totantsek = (anttimmar/60/60)+(antminuter/60)+antsekunder;
it would be multiplication instead of division
try this

Code: Select all

totantsek = (anttimmar*3600)+(antminuter*60)+antsekunder;

User avatar
ayu
Staff
Staff
Posts: 8082
Joined: 27 Aug 2005, 16:00
16
Contact:

Post by ayu »

oh lol...i forgot ;/
"The best place to hide a tree, is in a forest"

Post Reply