Reputation: 21
How to let printf run only once in loop, the P is argv so it will print Guess 4 times if the value of P is 4
while (h!=P) {
for (int i=0;i<P;i++)
{
n[i]=1,j[i]=1;
printf("\nGuess:");
scanf("%d",&guess[i]);
}
Output example
1 3 4 1
Guess:1 3 4 1
Guess:
Guess:
Guess:
4H0X
correct
1 4 1 2
Guess:4 1 2 1
Guess:
Guess:
Guess:
0H4X
Guess:
Upvotes: 0
Views: 1335
Reputation:
while (h!=P) {
printf("\nGuess:");
for (int i=0;i<P;i++)
{
n[i]=1,j[i]=1;
scanf("%d",&guess[i]);
}
I think just by putting that printf out from the FOR you can make it
Upvotes: 1
Reputation: 11
If you wnat only one "Guess" per for loop:
for (int i=0;i<P;i++) {
...
if (i == 0)
printf("\nGuess:");
...
}
Upvotes: 1