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!
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 ~
+ 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!
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.
0
Chee Chang Long thanks!
0
Chee Chang Long I tried using the for loop but the same error still occurred.
0
Can you let me see your code ?
0
Chee Chang Long it's at the top. 🙃
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;
}
0
Chee Chang Long yes it's just like that, just that "i" is named "counter".
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
0
Uchiha Itachi I'm using a raspberry pi.