Nested loops

Hi, i have a problem, if user chooses an N number of players, the program must has the limit of thta players, I mean if users chooses 3 players, it must shows N1 N2 N3 N1 N2 N3 N1 N2 ... for 200 times, but in my program if I choose 3, it always shows N3 N3 N3 N3 N3, how can I change it? thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>

using namespace std;

int main()
{

    int n=1, x=1, z=1, i=1; //n=numero de jugadores, x=numero para PUM, z=rondas
    char* PUM="PUM";

    cout << "1. Ingrese el numero de jugadores a participar" << endl;
    cin>>n;

    cout<< "2. Digite un numero menor que 10 y mayor que 0 para establecer el PUM"<<endl;
    cin>>x;
        while (x>=10)
        {cout<<"La opcion ingresada no es valida"<<endl;
        cout<< "2. Digite un numero menor que 10 y mayor que 0 para establecer el PUM"<<endl;
        cin>>x;}

{  for (z=1; z<=100; z=z+1)
{
        {if (z==x)
            cout<<"Jugador numero "<<i<<" ="<<PUM<<endl;
        else if (z%x==0)
            cout<<"Jugador numero "<<i<<" ="<<PUM<<endl;
        else if (z%10==x)
            cout<<"Jugador numero "<<i<<" ="<<PUM<<endl;
        else
            cout<<"Jugador numero "<<i<<" ="<<z<<endl;

        }}
    }



    return 0;
}
I’m sorry but I can’t understand what your code should do.

1) There’s a loop that’s required to iterate 100 times:
for (z=1; z<=100; z=z+1)
Why do you say it should repeat “N1 N2 N3 N1 N2 N3 N1 N2 ... for 200 times”?

2) When you say it should repeat “N1 N2 N3 ... for 200 times“, do you mean “Jugador numero 1”, “Jugador numero 2”, “Jugador numero 3” x 200 times?

3) The value of “i” isn’t modified from
i=1
at the beginning to:
cout<<"Jugador numero "<<i<<" ="<<PUM<<endl;
inside your loop.
It means “i” will always print “1“.
That’s a typical error due to the habit of declaring variables at the beginning of functions.
You’d be better declaring your variables *only* when you really need them.

4) What’s the PUM? Ok, I’m just curious :-)

5) What’s the rationale behind these modulo divisions?
(z%x==0) ... (z%10==x)

Please, have a look at the following code for more hints and describe better what your code should do.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Hi, i have a problem, if user chooses an N number of players, the program 
// must has the limit of thta players, I mean if users chooses 3 players, it 
// must shows N1 N2 N3 N1 N2 N3 N1 N2 ... for 200 times, but in my program if 
// I choose 3, it always shows N3 N3 N3 N3 N3, how can I change it? thanks
#include <iostream>

void waitForEnter();

int main()
{
    char PUM[] = "PUM";

    // Aren't there boundaries for the number of players?
    std::cout << "1. Ingrese el numero de jugadores a participar: ";
    int n = 0; // n = numero de jugadores
    std::cin >> n;
    std::cin.ignore(1);

    int x = 0; // x = numero para PUM
    do {
        std::cout<< "2. Digite un numero menor que 10 y mayor que 0 para "
                    "establecer el PUM: ";
        std::cin >> x;
        std::cin.ignore(1);
        if(x < 0 || 10 < x)
        {
            std::cout << "La opcion ingresada no es valida.\n";
        }
    } while(x < 0 || 10 < x);

    // Modify the following line according to the number of iterations you need
    for (int z=1; z<=4; z++)
    {
        std::cout << "\nIteration number " << z << '\n';
        for(int i=1; i<=n; i++)
        {
            std::cout << "Jugador numero " << i << " = " << PUM << '\n';
        }
    }
    waitForEnter();
    return 0;
}

void waitForEnter()
{
    std::cout << "\nPress ENTER to continue...\n";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

Wel... The user chooses N number of players and a X number called the PUM, the program must show the players saying consecutive numbers, If I choose 3 players and X=6(that means a player must say PUM instead of 6, multiple of 6 or a number ending in 6), then the program must show it like thisz N1=1, N2=2, N3=3, N1=4 N2=3 N3=PUM... for 200 times.
Do you want the solution or hints?
Topic archived. No new replies allowed.