所以,我遇到了这个程序结束的问题。它应该为每个正确猜测的硬币翻转奖励10分,并且在100次投掷结束时,每个玩家的正确答案的百分比以及总分,最后是宣布获胜者。我似乎有正确的百分比,但总得分的输出是乱码,我不知道如何让程序使用结果来宣布胜利者。帮助
body
答案 0 :(得分:1)
我强烈建议使用括号和缩进来正确格式化嵌套的if
语句。
if ( player=1)
if (turn == 1) // start of 2 player gaming
printf("\nPlayer 1, flip the coin. Player 2, take a guess.\n");// player 1 flip
else
printf("\nPlayer 2, it's your turn to flip the coin, Player 1 guess heads or tails.\n"); // player 2 flip
比
更难阅读if ( player=1) {
if (turn == 1) { // start of 2 player gaming
printf("\nPlayer 1, flip the coin. Player 2, take a guess.\n");// player 1 flip
} else {
printf("\nPlayer 2, it's your turn to flip the coin, Player 1 guess heads or tails.\n"); // player 2 flip
}
}
是的,如评论中所述
if ( player=1) {
应该是
if (player == 1) {
和
if (turn == 1)
Play = 1, turn = 0;
else
Play = 2, turn = 1;
应该是
if (turn == 1) {
Play = 1;
turn = 0;
} else {
Play = 2;
turn = 1;
}
您还在使用right1
,wrong1
,right2
和wrong2
而未初始化它们。
最后,在printf()
中,%'
如果您要打印百分号,则%%
应为#!/bin/bash
## This script will bounce a br interface if a member interface goes down.
## This will cause router BGP timers to reset, making outages last only seconds instead of minutes.
##
## This script is called by netplug on Vyos:
## /etc/netplug/linkdown.d/my-brdown
##
## Version History
## 1.0 - Initial version
##
LOCKDIR=/var/run/my-bridge-ctl
# Since we only have one br, not going to implement this right now.
#IGNORE_BRIDGES=()
IFACE=$1
#Remove the lock directory
function cleanup {
if rmdir $LOCKDIR; then
logger -is -t "my-bridge-ctl" -p "kern.info" "Finished"
else
logger -is -t "my-bridge-ctl" -p "kern.error" "Failed to remove lock directory '$LOCKDIR'"
exit 1
fi
}
if mkdir $LOCKDIR; then
#Ensure that if we "grabbed a lock", we release it
#Works for SIGTERM and SIGINT(Ctrl-C)
trap "cleanup" EXIT
logger -is -t "my-bridge-ctl" -p "kern.info" "Acquired lock, running"
# Processing starts here
IFACE_DESC=$(<"/sys/class/net/${IFACE}/ifalias")
IFACE_BR_DIR="/sys/class/net/${IFACE}/brport"
if [ ! -d "$IFACE_BR_DIR" ]; then
logger -is -t "my-bridge-ctl" -p "kern.warning" "Interface ${IFACE} (${IFACE_DESC-no desc}) went down. Not a member of a bridge. Skipping."
else
IFACE_BR_LINK=$(realpath "/sys/class/net/${IFACE}/master")
IFACE_BR_NAME=$(basename $IFACE_BR_LINK)
IFACE_BR_DESC=$(<"${IFACE_BR_LINK}/ifalias")
logger -is -t "my-bridge-ctl" -p "kern.warning" "Interface ${IFACE} (${IFACE_DESC:-no desc}) went down. Member of bridge ${IFACE_BR_NAME} (${IFACE_BR_DESC:-no desc})."
# TODO: Insert IGNORE_BRIDGE check here
find "${IFACE_BR_LINK}/brif" -type l -print0 | while IFS= read -r -d $'\0' IFACE_BR_MEMBER_LINK; do
IFACE_BR_MEMBER_NAME=$(basename $IFACE_BR_MEMBER_LINK)
logger -is -t "my-bridge-ctl" -p "kern.info" "Handling ${IFACE_BR_NAME} member interface ${IFACE_BR_MEMBER_NAME} (${IFACE_BR_MEMBER_LINK})."
# Actually do the bounce
ip link set dev ${IFACE_BR_MEMBER_NAME} down && sleep 2 && ip link set dev ${IFACE_BR_MEMBER_NAME} up
logger -is -t "my-bridge-ctl" -p "kern.info" "Interface ${IFACE_BR_MEMBER_NAME} bounced."
done
fi
sleep 5
else
logger -is -t "my-bridge-ctl" -p "kern.info" "Could not create lock directory '$LOCKDIR'"
exit 1
fi
。