[C] 选择器 →→→→→进入此内容的聊天室

来自 , 2020-09-04, 写在 C, 查看 110 次.
URL http://www.code666.cn/view/28b60a16
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<conio.h>
  4. #include<windows.h>
  5.  
  6. //设置光标位置
  7. void setCursorPosition(int x, int y);
  8.  
  9. int main(void)
  10. {
  11.         char ch1,ch2;
  12.         int a=0;
  13.        
  14.         setCursorPosition(0,0);
  15.         loop:printf("题目\n");
  16.         printf("○A、选项1\n");
  17.         printf("-------------------------------------------------------------------------------\n");
  18.         printf("○B、选项2\n");
  19.        
  20.         do{
  21.                 ch1=getch();
  22.                 switch(ch1){
  23.                         case 'a':
  24.                         case 'A':
  25.                         setCursorPosition(0,1);
  26.                         printf("\b \b●");
  27.                         setCursorPosition(0,3);
  28.                         printf("\b \b○");
  29.                         ch2=ch1;
  30.                         break;
  31.                
  32.                         case 'b':
  33.                         case 'B':
  34.                         setCursorPosition(0,3);
  35.                         printf("\b \b●");
  36.                         setCursorPosition(0,1);
  37.                         printf("\b \b○");
  38.                         ch2=ch1;
  39.                         break;
  40.                
  41.                        
  42.                         case '\r':
  43.                         if(a>0){
  44.                                 if(ch2=='A'||ch2=='a'){
  45.                                         system("cls");
  46.                                         setCursorPosition(0,0);
  47.                                         printf("恭喜你,答对了!");
  48.                                         getch();
  49.                                         return 0;}
  50.                                
  51.                                 else if(ch2=='b'||ch2=='B'){
  52.                                         system("cls");
  53.                                         setCursorPosition(0,0);
  54.                                         printf("真可惜,错了!");
  55.                                         ch2='0';
  56.                                         getch();
  57.                                         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");
  58.                                         goto loop;
  59.                                 }
  60.                         }
  61.                        
  62.                                 default:
  63.                                 setCursorPosition(6,7);
  64.                                 printf("输入错误");
  65.                                 Sleep(500);
  66.                                 printf("\b \b\b \b\b \b\b \b\b \b\b \b\b \b");}
  67.                
  68.                 a++;
  69.         }while(1);
  70.         return 0;
  71. }
  72.  
  73. void setCursorPosition(int x, int y){
  74.     COORD coord;
  75.     coord.X = x;
  76.     coord.Y = y;
  77.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  78. }

回复 "选择器"

这儿你可以回复上面这条便签

captcha