Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,161,581 members, 7,847,455 topics. Date: Saturday, 01 June 2024 at 05:44 PM

Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language (492 Views)

Post Your Programming Projects Ideas Here / Buy This Laptop And Start Your Programming Journey / 2019 Google Hash Code Programming Challenge For Professionals In Africa (2) (3) (4)

(1) (Reply) (Go Down)

Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by CodingSoft: 1:49pm On Jan 26, 2023
Add hours and minutes 12h:59m + 20h:53m in your programming language and give the result in hours and minutes like this: 33h:52m
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by TastyFriedPussy: 6:30pm On Jan 26, 2023
done!!
only god knows why NL wount let me post pictures

c++
#include <iostream>
using namespace std;
int main() {

int h1;
int m1;
int h2;
int m2;
int h3;
int m3;
cin>>h1;
cin>>m1;
cin>>h2;
cin>>m2;
h3=h1+h2;
m3=m1+m2;

for(int i=0;i<=m3;i++){
if(m3>59){
m3-=59;
h3+=1;
}
}
cout<<h3<< ":" <<m3;
return 0;
}

now if you will excuse me, i have some geometry to go and study tongue
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by CodingSoft: 6:51pm On Jan 26, 2023
TastyFriedPussy:
done!!
only god knows why NL wount let me post pictures

c++
#include <iostream>
using namespace std;
int main() {

int h1;
int m1;
int h2;
int m2;
int h3;
int m3;
cin>>h1;
cin>>m1;
cin>>h2;
cin>>m2;
h3=h1+h2;
m3=m1+m2;

for(int i=0;i<=m3;i++){
if(m3>59){
m3-=59;
h3+=1;
}
}
cout<<h3<< ":" <<m3;
return 0;
}

now if you will excuse me, i have some geometry to go and study tongue

Updated

Sorry this online compiler https://www.programiz.com/cpp-programming/online-compiler/ is not doing the right thing.
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by TastyFriedPussy: 6:56pm On Jan 26, 2023
CodingSoft:


Good try, but I ran your code on this online compiler https://www.programiz.com/cpp-programming/online-compiler/ and I got the result in the image.

The result should be: 33h:52m
work fine in my terminal. i don't know why it's not working for you.
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by TastyFriedPussy: 7:02pm On Jan 26, 2023
CodingSoft:


Good try, but I ran your code on this online compiler https://www.programiz.com/cpp-programming/online-compiler/ and I got the result in the image.

The result should be: 33h:52m when you add this two hours and minutes 12h:59m + 20h:53m

make sure you delete or clear everything on the online compiler first before you paste my code..


#include <iostream>
using namespace std;
int main() {

int h1;
int m1;
int h2;
int m2;
int h3;
int m3;
cin>>h1;
cin>>m1;
cin>>h2;
cin>>m2;
h3=h1+h2;
m3=m1+m2;

for(int i=0;i<=m3;i++){
if(m3>59){
m3-=59;
h3+=1;
}
}
cout<<h3<<"h"<< ":" <<m3<<"m";
return 0;
}
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by CodingSoft: 7:13pm On Jan 26, 2023
TastyFriedPussy:


make sure you delete or clear everything on the online compiler first before you paste my code..


#include <iostream>
using namespace std;
int main() {

int h1;
int m1;
int h2;
int m2;
int h3;
int m3;
cin>>h1;
cin>>m1;
cin>>h2;
cin>>m2;
h3=h1+h2;
m3=m1+m2;

for(int i=0;i<=m3;i++){
if(m3>59){
m3-=59;
h3+=1;
}
}
cout<<h3<<"h"<< ":" <<m3<<"m";
return 0;
}

I tried W3Schools online compiler and the result is an error.

The result should be: 33h:52m when you add this two hours and minutes 12h:59m + 20h:53m
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by LikeAking: 8:07pm On Jan 26, 2023
How much u go pay?
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by CodingSoft: 8:13pm On Jan 26, 2023
LikeAking:
How much u go pay?

It's to help programmers develop their skills. I have already implemented it in C# and that's why anyone that wants to try can use any language they prefer.
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by Alusiizizi(m): 9:12am On Jan 27, 2023
TastyFriedPussy:
done!!
only god knows why NL wount let me post pictures

c++
#include <iostream>
using namespace std;
int main() {

int h1;
int m1;
int h2;
int m2;
int h3;
int m3;
cin>>h1;
cin>>m1;
cin>>h2;
cin>>m2;
h3=h1+h2;
m3=m1+m2;

for(int i=0;i<=m3;i++){
if(m3>59){
m3-=59;
h3+=1;
}
}
cout<<h3<< ":" <<m3;
return 0;
}

now if you will excuse me, i have some geometry to go and study tongue

Why do you need the for loop? All you had to do was (m3-(m3 modulo 60))/60 + h3 for hours result and m3 modulo 60 for the minutes result.
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by Nesty1313(m): 5:04am On Apr 04, 2023
CodingSoft:
Add hours and minutes 12h:59m + 20h:53m in your programming language and give the result in hours and minutes like this: 33h:52m

Sir do u teach how to coding, I'm interested to learn
Re: Programming Challenge: Adding Time 12h:59m + 20h:53 In Your Programming Language by CodingSoft: 2:46pm On Apr 04, 2023
Nesty1313:

Sir do u teach how to coding, I'm interested to learn

What coding language do you want to learn? I should be able to put you in the right direction on how to learn it

1 Like

(1) (Reply)

The Rise Of Artificial Intelligence And Its Impact On Society / Python Help Needed ASAP / I have a few app ideas i am interested in developing, lets work together

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 29
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.