如何运行此代码来定义玩家数量?它只为一个玩家运行!!!! [英] How I Can Run This Code To Define Number Of Players ? it run only for one player !!!!

查看:75
本文介绍了如何运行此代码来定义玩家数量?它只为一个玩家运行!!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
// functions sign
int random();
void player_num(int);

// array define
typedef struct
{
	//int no_of_games;
	int stop;
	char name[10];
} gusty;
gusty max[20];

// variable declare 
int no_of_players;
// int i;
int p,
sum;
int i;

int main(void)
{
	time_t seconds;
	time(&seconds);
	srand((unsigned int)seconds);


	printf("please enter the no of players - ");
	scanf_s("%d", &no_of_players);

	player_num(no_of_players );
	
	
	

		//for (int i = 0; sum < max[i].name; i++)
	for (i = 0; i < no_of_players; i++) {
		while (sum < max[i].stop)
		{
			p = random();
			printf("random %d \n ", p);
			sum = sum + p;
			printf("sum = %d \n", sum);
		}
	}
	
	//printf("name  %s ", name);

	return 0;
}
int random()

{
	return rand() % 6 + 1;
}

void player_num(int no_of_players)
{
	int i = 0;
	for (i = 0; i < no_of_players; i++)
		
	{
		printf("name of player - ");
		scanf_s("%s", &max[i].name, 10);
		printf("no of stops - ");
		scanf_s("%d", &max[i].stop);
		
	}
}

推荐答案

我觉得是时候停止猜测你的是什么了代码正在做。是时候看到你的代码正在执行并确保它能达到预期的效果。



调试器是你的朋友。它会告诉你你的代码到底在做什么。

一步一步地执行,检查变量,你会发现它有一个停止做你期望的点。

掌握Visual Studio 2010中的调试 - 初学者指南 [ ^ ]

http://docs.oracle .com / javase / 7 / docs / technotes / tools / windows / jdb.html [ ^ ]

https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html [ ^ ]
I think it is time for you to stop guessing what your code is doing. It is time to see your code executing and ensuring that it does what you expect.

The debugger is your friend. It will show you what your code is really doing.
Follow the execution step by step, inspect variables and you will see that there is a point where it stop doing what you expect.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html[^]
https://www.jetbrains.com/idea/help/debugging-your-first-java-application.html[^]


你已在此问题中显示您的代码:任何人都可以告诉我如何从此打印名称? [ ^ ]



你被告知过CPallini和我,您的变量 xxxx 从未初始化(内容未定义)以及该怎么做(使用 i 代替)。虽然您没有修复此错误,但您的程序将无法按预期工作,甚至可能会崩溃。在这里提问时,你至少应该尝试给出的建议。



请阅读未初始化的变量 - 维基百科,免费的百科全书 [ ^ ]了解发生了什么。





问题已由海报编辑以修复上述错误(已删除变量 xxxx 并使用 i 代替。

[/ EDIT]
You have shown your code already in this question: Can Anyone Please Tell Me How I Can Print Name From This ?[^]

There you have been told by CPallini and me that your variable xxxx is never initialised (the content is undefined) and what to do (using i instead). While you did not fix this error your program will not work as expected or might even crash. When asking questions here you should at least try the given advices.

Please read Uninitialized variable - Wikipedia, the free encyclopedia[^] to understand what is happening.


Question has been edited by poster to fix the above error (removed variable xxxx and used i instead).
[/EDIT]


这篇关于如何运行此代码来定义玩家数量?它只为一个玩家运行!!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆