0
Create a timer program that will take the number of seconds as input, output the remaining time and countdown to 0.
Hey guys I'm beginner here and don't know how to do this every time I tried I got so many numbers in negative part. Can someone please help me.
27 odpowiedzi
+ 29
I think this is something what you're looking for!
https://code.sololearn.com/cUWS8NP8FWTD/?ref=app
+ 13
package main
import "fmt"
func ( x *Timer ) tick(){
x.id++
fmt.Println(x.id)
}
type Timer struct {
value string
id int
}
func main() {
var x int
fmt.Scanln(&x)
t := Timer{"timer1", 0}
for i:=0;i<x;i++ {
t.tick()
}
}
+ 5
C++/C Challengerโ๏ธโ
โ๏ธ
Thank you so much sir for your help โบ๏ธโบ๏ธ
+ 4
Look in the beginning of the course to learn about 'input' and 'loops'
+ 4
# take the number as input
number = int(input())
#use a while loop for the countdown
while number >=0:print(number);number = number - 1
+ 3
You can either use a for loop or add a second condition to stop seconds below 0
+ 3
create code on your language and link on your code, better remove this topic and create new topic with code , question and link on your code. In code will write comment โwhat do you want to doโexample: input and output
+ 3
#include <iostream>
using namespace std;
int main()
{
int seconds;
cin >> seconds;
while (seconds >= 0){
cout <<"timer : "<<seconds<<endl;
seconds=seconds -1;
}
return 0;
}
+ 2
Nasif Rahman
#include <iostream>
using namespace std;
int main()
{
int seconds = 3 ;
while (seconds < 4){
cout << seconds << endl ;
seconds = seconds - 1;
}
return 0;
}
+ 2
Olivia I tried but i got nothing There's nothing about it
+ 2
Ticking Timer
You are building a Timer app that should count up to a given number.
Your program needs to take a number as input and make the Timer tick that number of times.
The code in main initializes a Timer and takes a number as input. Then it calls the tick() method for the Timer the given number of times.
Define the Timer struct with two fields: id and value, and define the tick() method, which should increment the value by one and output its current value.
package main
import "fmt"
func main() {
var x int
fmt.Scanln(&x)
t := Timer{"timer1", 0}
for i:=0;i<x;i++ {
t.tick()
}
}
can anyone answer it in golang please
+ 2
#include <iostream>
using namespace std;
int main()
{
int seconds;
cin>>seconds;
//your code goes here
while (seconds >= 0) {
cout << seconds << endl;
seconds--;
}
return 0;
}
+ 2
// thank me later
#include <iostream>
using namespace std;
int main()
{
int seconds;
cin >> seconds;
while (0 <= seconds){
cout << seconds << endl;
seconds--;
}
return 0;
}
+ 2
At python
--------------------
# take the number as input
number = int(input())
#use a while loop for the countdown
while number >= 0:
print(number)
number -= 1
+ 1
Olivia some examples please
+ 1
#include <iostream>
using namespace std;
int main()
{
int seconds;
cin>>seconds;
//your code goes here
cout << seconds << endl;
while (seconds > 0){
seconds --;
cout << seconds << endl;
}
return 0;
}
+ 1
let num = parseInt(readLine(), 10);
//your code goes here
while (num > -1) {
console.log(num);
num--;
}
using javascript
+ 1
number =int(input())
while number>=0:
print(number)
number=number-1
+ 1
# take the number as input
number = int(input())
#use a while loop for the countdown
while number in reversed(range(4)):
print(number)
number = number - 1
while number in reversed(range(6)):
print(number)
number = number - 1
+ 1
# take the number as input
number = int(input())
#use a while loop for the countdown