+ 4

Possible to iterate a cin command?

I was trying to iterate a cin command on here its not really working out fine... wondering if its the compiler here or maybe its wrong to do that... just trying to learn. check my code to see(leave a comment pls)

3rd Jul 2017, 3:41 AM
Gemini
Gemini - avatar
6 Respuestas
+ 11
// This is your code #include <iostream> using namespace std; // Keep in mind that global variables are not necessary here. int seven_count; int three_count; int data[5]; int index; int data_ite; int main() { seven_count = 0; three_count = 0; cout << "Enter 5 numbers: "<<endl; data_ite = 0; // Here, brackets should be used to enclose cin statement and ++data_ite within while statement block. // That said, it should be noted that input and loops don't work well on Code Playground, and will not work even if your code is correct. This is a known problem on our SL IDE. // Try compiling this on a desktop compiler. :> while(data_ite < 5) cin >> data[data_ite]; ++data_ite; // This is fine. for (index = 0;index < 5;++index){ if (data[index] == 3) ++three_count; if (data[index] == 7) ++seven_count; } cout << "Threes: " << three_count << " Sevens: " << seven_count << endl; return 0; }
3rd Jul 2017, 3:55 AM
Hatsy Rei
Hatsy Rei - avatar
+ 10
By iterating cin, do you mean putting cin inside a loop, or do you mean evaluating user input using conditional statements? I've checked your codes and couldn't find anything regarding the former. Which one are you referring to?
3rd Jul 2017, 3:43 AM
Hatsy Rei
Hatsy Rei - avatar
+ 4
Okay that helps
3rd Jul 2017, 4:01 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 3
@Hastyrei. recheck pls #thanks
3rd Jul 2017, 3:47 AM
Gemini
Gemini - avatar
+ 2
@Hastyrei. thanks a lot for that... much appreciated
3rd Jul 2017, 3:59 AM
Gemini
Gemini - avatar
+ 1
like if you want to enter 5 inputs so do it like this: 1 2 3 4 5. the input after a space will be recognised as another input
3rd Jul 2017, 7:28 AM
Bruh