我是C編程新手,在C編程中我無法掌握如何使用while
和if
函數。理解循環的問題
目前我有這個粗略的嘗試在開始我的程序。我目前收到錯誤消息'expected expression',其中有'if語句',但我相信代碼中有更多錯誤,因爲它不會執行我正在尋找的操作。
理想情況下,我想讓用戶繼續獲得相同的錯誤信息,直到他們從1-3正確輸入一個數字,然後只要他們輸入正確的數字,它就會存儲它並繼續前進到下一步。對不起,我在這方面很新,而且我一直對所閱讀的所有不同的教程感到困惑,因爲我正在閱讀循環和if語句。
任何幫助將不勝感激。
#include <stdio.h>
int main(void)
{
printf("Welcome to the ROBOT GAME!\n"
"To help you visualize draw a three by three board on a piece of paper.\n"
"Please enter the column of your starting point.\n"
"Keep numbers in the range of one to three.\n");
int a;
scanf("%i", &a);
while(a<1||a>3)
{
printf("Error: Sorry try again.\n"
"Please enter the column of your starting point.\n");
int a;
scanf("%i", &a);
break;
if(a=>1 && a<=3)
printf("Please enter the row of your starting point. Keep numbers in the range of one to three.\n");
int b;
scanf("%i", &b);
}
}
它看起來像'if'語句需要打開和關閉大括號(即''''和'}')。否則,您*有條件*打印郵件,但*無條件*接受輸入。 – jww 2014-09-20 20:53:05
總是會使用「break」。關掉你的電腦,拿一支鉛筆和一張紙,先畫一個流程圖。 – usr2564301 2014-09-20 20:56:13
[C程序問題與循環]的可能重複(http://stackoverflow.com/questions/25945438/c-program-problems-with-loops) – hugomg 2014-09-20 20:59:52