用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c代码库

选择器

2017-07-05 作者: 一只爬不上树的猴子举报

[c]代码库

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
 
//设置光标位置
void setCursorPosition(int x, int y);
 
int main(void)
{
    char ch1,ch2;
    int a=0;
     
    setCursorPosition(0,0);
    loop:printf("题目\n");
    printf("○A、选项1\n");
    printf("-------------------------------------------------------------------------------\n");
    printf("○B、选项2\n");
     
    do{
        ch1=getch();
        switch(ch1){
            case 'a':
            case 'A':
            setCursorPosition(0,1);
            printf("\b \b●");
            setCursorPosition(0,3);
            printf("\b \b○");
            ch2=ch1;
            break;
         
            case 'b':
            case 'B':
            setCursorPosition(0,3);
            printf("\b \b●");
            setCursorPosition(0,1);
            printf("\b \b○");
            ch2=ch1;
            break;
         
             
            case '\r':
            if(a>0){
                if(ch2=='A'||ch2=='a'){
                    system("cls");
                    setCursorPosition(0,0);
                    printf("恭喜你,答对了!");
                    getch();
                    return 0;}
                 
                else if(ch2=='b'||ch2=='B'){
                    system("cls");
                    setCursorPosition(0,0);
                    printf("真可惜,错了!");
                    ch2='0';
                    getch();
                    printf("\b \b\b \b\b \b\b\ \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b\b \b");
                    goto loop;
                }
            }
             
                default:
                setCursorPosition(6,7);
                printf("输入错误");
                Sleep(500);
                printf("\b \b\b \b\b \b\b \b\b \b\b \b\b \b");}
         
        a++;
    }while(1);
    return 0;
}
 
void setCursorPosition(int x, int y){
    COORD coord;
    coord.X = x;
    coord.Y = y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...