S-K
S-K

Reputation: 79

Repeat a function 1000 times

I've been searching for an answer and it seems like I can't find it. Can anyone help me in calling void function into main 1000 times?

Here's the code:

    void sahovnica()
     {
         int dolzina = 8;
         cout<<""<< endl;
         cout<<""<< endl;
         char znak = 'X';
         int vsakadruga = dolzina % 2;
         for(int i=0; i<dolzina; i++)
         {
             for(int j=0; j<dolzina; j++)
             {
                      cout << znak;
                      if( znak == 'X' )
                          znak = 'O';
                      else znak = 'X';
             }
             cout << endl;
             if(!vsakadruga)
             {
                     if( znak == 'X' )
                             znak = 'O';
                     else znak = 'X';
             }
         }
         cout<<""<< endl;
     }
______________________________________

int main(){

/*lot of functions here......
 *............
 *...........*/
    if (nadaljevanje != 1 && nadaljevanje != 2){
            cout<<"Ponovno zazenite program. Niste vnesli ne 1 ne 2."<<endl;
            return 0;
        }
        else if (nadaljevanje ==2){
                  cout<<"Pridite se kdaj. Se vidimo!"<<endl;
                  return 0;
        }

         else if (nadaljevanje ==1){
           sahovnica();//Need to call this "sahovnica" function 1000 times here.

        }


        return 0;
    }

If you need any more informations, please let me know down bellow. Thanks for all the answers in advance!

Upvotes: 1

Views: 2118

Answers (1)

user5473178
user5473178

Reputation:

you can put your function call inside a loop :

else if (nadaljevanje ==1){
for(int i = 0; i<1000;i++){
       sahovnica();//Need to call this "sahovnica" function 1000 times here.
}

    }

Upvotes: 5

Related Questions