Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C++
#include<iostream>

using namespace std;

int main()
{
	int detik;
	int menit;
	int jam;
	int total_detik;
	int sisa;
	
	cout << " ======Hitung waktu====== " <<endl;
 cout="" <<="" "="" masukkan="" detik="" :";
="" cin="">> detik;
	
	jam = total_detik / 3600;
	sisa = total_detik % 3600;
	menit = sisa / 60;
	detik = sisa % 60;
	
	cout << " Jadi, " << total_detik << " detik adalah sama dengan " << jam << " jam " << menit << " menit " << detik << " detik ";
	
	return 0;
	}

What I have tried:

I tried all day , please help me. I can't see the answer when I run.
When I put the number of detik( seconds) : 3600
But the answer is not calculated. Example : Put Number of seconds : 3600. The answer of my code is [Jadi, 0 detik adalah sama dengan 0jam 0 menit 0 detik]  saya mau di saat saya meletakan angka 3600 detik. Langsung keluar [ Jadi, 3600 detik adalah 1 jam 0 menit 0 detik. 
Is my course code is wrong or something? Pls help me. Thanks in advance ^_^
Posted
Updated 3-Sep-22 1:53am
v3
Comments
Patrice T 2-Sep-22 9:04am    
What is the meaning of tittle ?
- you see nothing ?
- Result is wrong ?
- input disappear ?
Rick York 2-Sep-22 16:21pm    
The word is please.
Richard MacCutchan 3-Sep-22 9:01am    
I pointed out your mistake yesterday.

Look at your code:
C++
cin="">> detik;

 jam = total_detik / 3600;
 sisa = total_detik % 3600;

You try to calculate the value of jam (and sisa) by dividing total_detik by 3600. But you have never added any values into total_detik, so whatever results you get will not be valid. You need to rethink exactly what this code is supposed to do.
 
Share this answer
 
Comments
CPallini 2-Sep-22 8:40am    
5.
Taking Richard's cue, we could try:
C++
#include<iostream>
  
using namespace std;

int main()
{
  int detik;
  int menit;
  int jam;
  int total_detik;
  int sisa;

  cout << " ======Hitung waktu====== " << endl;
  cout << " masukkan total detik :";
  cin >> total_detik;

  jam = total_detik / 3600;
  sisa = total_detik % 3600;
  menit = sisa / 60;
  detik = sisa % 60;

  cout << " Jadi, " << total_detik << " detik adalah sama dengan " << jam << " jam " << menit << " menit " << detik << " detik\n";

  // wait for user input
  cin.ignore(256, '\n');
  cin.get();
}
 
Share this answer
 
v2
Comments
Patrice T 6-Sep-22 2:28am    
+5
Quote:
I tried all day , please help me. I can't see the answer when I run.

In your question you didn't told if answer is wrong or if nothing is printed or if screen is cleaned before you see what the program printed and if it printed anything.
- add checkpoints in your program, to ensure the execution reached certain point.
C++
#include<iostream>

using namespace std;

int main()
{
	int detik;
	int menit;
	int jam;
	int total_detik;
	int sisa;
	
	cout << "Checkpoint: Program Start";
	cout << " ======Hitung waktu====== " <<endl;
 cout="" <<="" "="" masukkan="" detik="" :";
="" cin="">> detik;
	
	jam = total_detik / 3600;
	sisa = total_detik % 3600;
	menit = sisa / 60;
	detik = sisa % 60;
	cout << "Checkpoint: Calculation done";	

	cout << " Jadi, " << total_detik << " detik adalah sama dengan " << jam << " jam " << menit << " menit " << detik << " detik ";
	
	cout << "Checkpoint: Program End";
	return 0;
	}


- Use the debugger to investigate what is going on in your program.
Your code do not behave the way you expect, or you don't understand why !

There is an almost universal solution: Run your code on debugger step by step, inspect variables.
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't know what your code is supposed to do, it don't find bugs, it just help you to by showing you what is going on. When the code don't do what is expected, you are close to a bug.
To see what your code is doing: Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]

1.11 — Debugging your program (stepping and breakpoints) | Learn C++[^]

The debugger is here to only show you what your code is doing and your task is to compare with what it should do.
 
Share this answer
 
Comments
jonathan legends 3-Sep-22 5:48am    
When I put the number of detik(second) :3600
Jadi, 0 detik adalah 0 jam 0 menit 0 detik.
The answer must be [ Jadi, 3600 detik adalah 1 jam 0 menit 0 detik]
What should I do 😭 I'm still newbie
Patrice T 3-Sep-22 7:13am    
Ok, so wrong answer.
Use Improve question to update your question.
So that everyone can pay attention to this information.
Patrice T 3-Sep-22 7:17am    
So learn the debugger, or read caredukky other solutions.
Look at your code:
#include<iostream>


	int detik;
...
	int total_detik;
...
    cin="">> detik;
	
	jam = total_detik / 3600;
	sisa = total_detik % 3600;
	menit = sisa / 60;
	detik = sisa % 60;
	
	cout << " Jadi, " << total_detik << " detik adalah sama dengan " << jam << " jam " << menit << " menit " << detik << " detik ";
	
	return 0;
	}
Between declaring it and using it's content, you don't give total_detik any value at all.
You read a value into detik, but you don't use it!
Try changing this line:
cin >> detik;
To this:
cin >> total_detik;
And see what happens.

To be honest, if you'd followed the advice you were given ages ago and used the debugger, you would have seen exactly what was going on.
The debugger is your friend: it's much faster than asking others to solve it for you ...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900