• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with a small C++ calculator program

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there , I am having a problem with a challenge from a C++ book. It was actually asking to give the display of how many minutes or hours or days. But of course the results are not accurate depending o0n how many seconds the users is asking to enter. So far I have successfully solve the 2 first conditional (minutes and hours) But I am having trouble with the days. When I enter for example 90000 seconds it should give as answer 1 day(86400 s) and 1 hour(3600) But it just gives me 1 day and zero minutes. I honestly think it is a math and logic issue as I am not strong in math at all but I have spent a good amount of time on it so I would appreciate a little help with this program. Thank you so much.

[
 
Fred Masen
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have found something . I changed the last line of code to :


90000
 number of days is : 1 and the hours is : 25 which seems to be correct. But how could I had the minutes as well as the seconds in this last line of code ?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't try to mix colour and size tags with code tags. They don't work together.
Please format your code with indentation and correct line lengths (look at line 27) and remove all the unnecessary empty lines. It is you who will have the most difficulty if an error occurs and poor formatting obscures it.
Why are you using 60 and 3600 in lines 17 and 19 after you declared those consts? Why are you using 3600 in line 21 rather than DAY (which isn't 3600)? What does remainMinutes mean? It doesn't seem to count anything in minutes. Inaccurate variable names is another good technique for confusing yourself.
Why do your ifs not cover the entire range of values? What happens if you enter 50″? Your tests for the ifs are also too complicated. This is what you want:-or a different versionConsider changing int to unsigned int throughout because you won't be permitting negative values.

I shall leave the question in your second post as “an exercise for the reader”.
 
Fred Masen
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank Yoou
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic