+ 1

timelimit exeeded?

i am trying to make a program where youre able to input 20 names and then output some of them with numbers but i get an error with: timelimit exeeded. #include <iostream> using namespace std; int main() { int selected; string arr[20]; for(int i = 0; i < 20; i++) std::cin >> arr[i]; cin >> selected; cout << "These people didnt make there homework:" << endl << arr[selected] << endl; return 0 }

31st Oct 2016, 12:19 PM
Laurens Verbruggen
Laurens Verbruggen - avatar
6 Réponses
+ 1
maybe when you run it you write only 1 input, but if you write the first string then press enter, write the second string then press enter (for 20 times) and write the number (because the last input is an integer) it works. Example: (run the program) (1st string) John (2nd string) James . . (20th string) Bart (the variable selected) 5 then submit
31st Oct 2016, 1:11 PM
Leo Flame
Leo Flame - avatar
+ 1
it worked but now it gives a weird error about the printf code. i don't know the scanf so i dont know what it means
31st Oct 2016, 1:11 PM
Laurens Verbruggen
Laurens Verbruggen - avatar
+ 1
thank you leo! but what does timelimit mean? it could help in future problems.
31st Oct 2016, 1:15 PM
Laurens Verbruggen
Laurens Verbruggen - avatar
+ 1
because you don't write the remain of strings so the for loop wait the next input but if you write this code in your PC and run it you will not have this problem
31st Oct 2016, 1:18 PM
Leo Flame
Leo Flame - avatar
0
It may help you using "scanf" instead of "cin" and including "cstdio" as a header file.
31st Oct 2016, 12:58 PM
Shovan Lal Saha
Shovan Lal Saha - avatar
0
leave the code that you wrote (change std::cin with cin) and try that I sayed
31st Oct 2016, 1:16 PM
Leo Flame
Leo Flame - avatar