用循环C语言程序问题 [英] C Program Problems with Loops

查看:105
本文介绍了用循环C语言程序问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的编程和目前工作的一个程序(它没有在附近完成的),但我想不出如何以及为什么这是不行的。我必须失去了与'如果'和'其他'

东西

 的#include<&stdio.h中GT;INT主要(无效)
{
    的printf(欢迎来到机器人GAME!\\ n
           请输入您的出发点列保存号码一到三的范围\\ n。);    诠释A,B;
    如果(1 << = A&下; = 3);
    {
        scanf函数(%i的,&安培;一);
    }
    其他
       {
        的printf(对不起再试一次。);
       }    的printf(请输入您的出发点的行保留号码一到三的范围\\ n。);
    如果(1&GT; = b将; = 3);
        scanf函数(%i的,和b);
    的printf(什么是你的下一步行动?选择\\ n
           1.右键\\ n
           2.Left \\ n
           3.Up \\ n
           4.Down \\ n);}


解决方案

第一个臭虫

  INT A,B;
如果(1 << = A&下; = 3);

您如何检查 A 如果的条件,甚至是未初始化?首先通过初始化值 A B (用 1 )然后去解决二错误

第二个错误

 如果(1 << = A&LT; = 3);

删除; 如果条件,然后去修复第三错误

第三个错误

 如果(1 << = A&LT; = 3);

是不是该做你想要什么。它应该

 如果(A&GT; = 1&安培;&安培; A&LT; = 3)

现在同样适用于如果(1&GT; = B&LT; = 3); 按照每个上面的步骤来解决这个问题。

第四错误

您有 INT主要(无效)。因此需要返回0 在结束

I'm very new to programming and currently working on a program (it is no where near done) but I cannot figure out how and why this won't work. I must be missing something with the 'if' and 'else'

#include <stdio.h>

int main(void)
{
    printf("Welcome to the ROBOT GAME!\n"
           "Please enter the column of your starting point. Keep numbers in the range of one to three.\n");

    int a, b;
    if(1<=a<=3);
    {
        scanf("%i", &a);
    }
    else 
       {
        printf("Sorry try again.");
       }

    printf("Please enter the row of your starting point.  Keep numbers in the range of one to three.\n");
    if(1>=b<=3);
        scanf("%i", &b);
    printf("What is your next move? Pick\n"
           "1.Right\n"
           "2.Left\n"
           "3.Up\n"
           "4.Down\n");

}

解决方案

First Bug

int a, b;
if(1<=a<=3);

How can you check a in if condition even it not initialized?. First Fix it by initializing value to a and b ( with 1) Then go for to fix Second Bug

Second Bug

if(1<=a<=3);

Remove ; after if condition then go for Fix Third Bug

Third Bug

if(1<=a<=3);

is not suppose to do what you want. it should

if(a>= 1 && a <= 3)

Now same is true for if(1>=b<=3); Follow every above steps to fix this.

Fourth Bug

You have int main(void). So need to return 0 at end of main

这篇关于用循环C语言程序问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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