0

Shouldnt this ask for a second imput if the number is negative

#include <iostream> using namespace std; int factorial(int n) { if (n<=1) { return 1; } else { return n * factorial(n-1); } } int main() { int x; cin >> x; while(x<=-1){ cout << "try again"; cin >> x;} cout << factorial(x); }

3rd Apr 2017, 2:23 PM
Rwby Panda
Rwby Panda - avatar
5 Antworten
+ 15
The code runs fine, just tried it out.
3rd Apr 2017, 2:50 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 4
If you're running it on codeplayground, you can only get one input at start of run-time. Just the way code playground is designed.
3rd Apr 2017, 3:02 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
AIDE-IDE might be ok for mobile. Never actually tried it, just an assumption on number of downloads.
3rd Apr 2017, 5:30 PM
Rrestoring faith
Rrestoring faith - avatar
0
kk thanks
3rd Apr 2017, 4:11 PM
Rwby Panda
Rwby Panda - avatar
0
whats a app or online program for mobile devices thag will allow me to do multiple inputs and maybe even small c++ games like snake or pacman or older games just to get the theory down
3rd Apr 2017, 4:13 PM
Rwby Panda
Rwby Panda - avatar