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');
}
|