5 student picked up 5 balls. they do not choose same number
but during print out process, the program is writing different ball number
i dont know why?

#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

int main(int argc, char *argv[])
{
int i;
int ogr[5] = {0};  // student..
int top[6] = {0};  // ball..
int secenek; // choice..

    for(i = 0; i < 5; i++)
    {
          
                cout <<"which ball does the student pick up? " << i + 1<< ".student= ";
                cin >> secenek;
                
                while(secenek <= 0 || secenek > 5){
                cout <<"enter number between 1-5 ";
                cin >>secenek;
                }
                
                if(top[secenek] != 0)
                {
                                do{
                                     printf("retry ");
                                     cin >> secenek;
                                     
                                     while(secenek <= 0 || secenek > 5){
                                     cout << "enter number between 1-5  ";
                                     cin >> secenek;
                                     }
                                     
                                     }while(top[secenek] != 0);
                                    
                }
                top[secenek] = 1;
                ogr[i-1] = secenek;
                
          
          
    }
    
    
    
for(i = 1;i <= 5; i++)
{
  cout << i << ".student picked the ball..." << ogr[i - 1] << "\n";
}

getch();

return 0;

}

Line 40 is wrong, what happens there when i == 0 ?

thank you it should be i not i-1

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.