0

I have two questions with this code:

void main{ int counter = 0; int registeredStudents [10]; while (counter < 10) { cout << "Student #" << counter + 1 << ":\n"; cin >> registeredStudents [counter]; counter++; } } 1. It won't let me use void for the main function. 2. The program allows me to give the first input for the array, but then just prints "Student #2:", "Student #3", etc. without letting me give more input. Thanks if you can give some answers!

20th Aug 2019, 11:43 PM
Thomas Wald
Thomas Wald - avatar
11 Respuestas
+ 1
1. Try change main function to int main() 2. Don't use while loop, try use for loop Hope it may help you ~
21st Aug 2019, 1:29 AM
Uchiha Itachi
Uchiha Itachi - avatar
+ 1
In my opinion, mostly void use for the function, and it have its own parameter and return value to the main. If you need to know more about this , go here to see. http://www.cs.fsu.edu/~cop3014p/lectures/ch7/index.html https://stackoverflow.com/questions/3156423/why-dont-we-use-void-in-main Good Luck!
21st Aug 2019, 1:52 AM
Uchiha Itachi
Uchiha Itachi - avatar
0
Thanks Chee Chang Long; BTW I know that you usually use int for the main function, I was just wondering why I can't use void as an alternative.
21st Aug 2019, 1:42 AM
Thomas Wald
Thomas Wald - avatar
0
Chee Chang Long thanks!
21st Aug 2019, 7:47 PM
Thomas Wald
Thomas Wald - avatar
0
Chee Chang Long I tried using the for loop but the same error still occurred.
21st Aug 2019, 10:28 PM
Thomas Wald
Thomas Wald - avatar
0
Can you let me see your code ?
22nd Aug 2019, 1:28 AM
Uchiha Itachi
Uchiha Itachi - avatar
0
Chee Chang Long it's at the top. 🙃
22nd Aug 2019, 8:11 PM
Thomas Wald
Thomas Wald - avatar
0
I mean the your code after add for loop. Nevermind here the examples, #include <iostream> using namespace std; int main() { int registeredStudents [10]; for(int i =1; i<11; i++) { cout<<"Student "<< i << " :"; cin>>registeredStudents[i]; } return 0; }
23rd Aug 2019, 1:16 AM
Uchiha Itachi
Uchiha Itachi - avatar
0
Chee Chang Long yes it's just like that, just that "i" is named "counter".
23rd Aug 2019, 3:30 AM
Thomas Wald
Thomas Wald - avatar
0
Don't use Sololearn console. It cant support for getting user input more than one. Try use other online C++ compiler https://www.onlinegdb.com/online_c++_compiler
23rd Aug 2019, 6:04 AM
Uchiha Itachi
Uchiha Itachi - avatar
0
Uchiha Itachi I'm using a raspberry pi.
23rd Aug 2019, 8:20 PM
Thomas Wald
Thomas Wald - avatar