+ 1

What did I do wrong? Pls help

#include <iostream> using namespace std; int main() { //your code goes here int bus=50; int input, remainder; cin>> input; while(remainder > 49){ input - bus = remainder; } int bus % remainder = ans; cout << ans; return 0; }

10th Aug 2022, 5:38 PM
Merie Henry
Merie Henry - avatar
5 Antworten
+ 2
Equation must be in the right side of the assignment operator, and the result will stored left side of assignment operator . That is, remainder = input - bus; (inside the while loop) int ans = bus% remainder;
10th Aug 2022, 5:47 PM
Pallavi Jha
Pallavi Jha - avatar
+ 1
No need to use while loop you can directly get the result. What did I do wrong? Pls help #include <iostream> using namespace std; int main() { //your code goes here int bus=50; int input, remainder; cin>> input; remainder= input - bus ; int ans= bus % remainder; cout << ans; return 0; } Here you go.
10th Aug 2022, 6:39 PM
Pallavi Jha
Pallavi Jha - avatar
+ 1
Timeout is happening because if comparing an uninitialized variable. But i think there are some more mistakes. I tried to fix it for you, is that how the code should work? #include <iostream> using namespace std; int main() { //your code goes here int bus=50; int input, remainder; cin >> input; remainder = input; while(remainder > 49) { remainder -= bus; } cout << bus - remainder; return 0; } But there is also a way without a loop, which performs much faster, especally for high input numbers. Just modulo the input with the bus size to get passengers in the last/not full bus and substrakt that from the bus size to get the empty seats
10th Aug 2022, 11:14 PM
Janosch Renner
Janosch Renner - avatar
+ 1
This was my solution without loop: #include <iostream> using namespace std; int main() { //your code goes here int waiting; cin >> waiting; int left_seat = 50 - waiting % 50; cout << left_seat; return 0; }
10th Aug 2022, 11:17 PM
Janosch Renner
Janosch Renner - avatar
0
Thx but I'm getting a... "Timeout. Dumped core";
10th Aug 2022, 6:04 PM
Merie Henry
Merie Henry - avatar