| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 354 人关注过本帖
标题:简单的循环问题
只看楼主 加入收藏
zhsb8529869
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2010-6-28
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:3 
简单的循环问题
#include "stdio.h"
static void Main(string[]args)
{
    int id,pwd;
    do
    {
        printf("请输入您的名字代号:");
        printf("(1)小王,(2)小梁,(3)小赵");
        scanf("%d",&id);
        printf("请输入密码:");
        scanf("%d",&pwd);
        switch(id)
        {
            case 1:
                 if(pwd=="xiaowang")
                 {
                     printf("密码正确!");
                    flag=true;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 if(pwd=="xiaoliang");
                 {
                     printf("密码正确!");
                     flag=true;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 if(pwd=="xiaozhao");
                 {
                     printf("密码正确!");
                     flag=true;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 break;
             default:
                  printf("查无此人");break;
            
        }
        
    }while(!flag);   
    printf("谢谢使用,请按回车键退出!");
   
}


这本来是C#里的代码,我把他改了一下,但是运行不了....请问什么原因
搜索更多相关主题的帖子: include 输入密码 
2010-08-02 14:41
lampeter123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
收藏
得分:0 
void main()

pwd的类型不正确

[ 本帖最后由 lampeter123 于 2010-8-2 15:02 编辑 ]

你的优秀和我的人生无关!!!!
    
    我要过的,是属于我自己的生活~~~
2010-08-02 15:00
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:5 
#include "stdio.h"
static void Main(string[]args)//这里有问题,形参没有定义类型
{
    int id,pwd;//pwd要改成字符型的
    do
    {
        printf("请输入您的名字代号:");
        printf("(1)小王,(2)小梁,(3)小赵");
        scanf("%d",&id);
        printf("请输入密码:");
        scanf("%d",&pwd);//%d应该改成%s,后面的&去掉
        switch(id)
        {
            case 1:
                 if(pwd=="xiaowang")
                 {
                     printf("密码正确!");
                    flag=true;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 if(pwd=="xiaoliang");
                 {
                     printf("密码正确!");
                     flag=true;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 if(pwd=="xiaozhao");
                 {
                     printf("密码正确!");
                     flag=true;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 break;
             default:
                  printf("查无此人");break;
            
        }
        
    }while(!flag);   
    printf("谢谢使用,请按回车键退出!");
   
}

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-08-02 15:37
ggyy4k
Rank: 5Rank: 5
等 级:职业侠客
帖 子:111
专家分:334
注 册:2010-6-28
收藏
得分:5 
回复 楼主 zhsb8529869
不知道楼主是改成.c还是.cpp,下面是我按.c语法修改的,编译通过
#include "stdio.h"
void main()
{
    int id, flag=0;
    char pwd[10];
    do
    {
        printf("请输入您的名字代号:");
        printf("(1)小王,(2)小梁,(3)小赵");
        scanf("%d",&id);
        printf("请输入密码:");
        scanf("%s",pwd);
        switch(id)
        {
            case 1:if(!strcmp(pwd,"xiaowang"))
                 {
                     printf("密码正确!");
                    flag=1;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 break;
            case 2:if(!strcmp(pwd,"xiaoliang"))
                 {
                     printf("密码正确!");
                     flag=1;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 break;
            case 3:if(!strcmp(pwd,"xiaozhao"))
                 {
                     printf("密码正确!");
                     flag=1;
                 }
                 else
                 {
                     printf("密码错误!");
                 }
                 break;

             default:
                  printf("查无此人\n");break;
            
        }
        
    }while (!flag);
    printf("谢谢使用,请按回车键退出!");
}
2010-08-02 15:53
快速回复:简单的循环问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015872 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved