-2

基本上,我需要编写一个程序,程序要求用户输入特定的数字来获得特定的形状。比如1代表椭圆,2代表矩形等等,程序需要不断要求用户输入数字,直到用户输入数字9结束程序。这是 Turbo C 中的最终工作代码

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

int main ()
{
clrscr();
 int x=0;

 while(x != 9)
 {
 printf ("Enter 1,2,3 and 4 for differeten shape and 9 to exit: ");
 scanf ("%d",&x);

 if (x == 1)
 {
     printf ( "*********\n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   "*********\n");
 }

 else if (x == 2)
 {
     printf ("   ***   \n"
   " *     * \n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   "*       *\n"
   " *     * \n"
   "   ***   \n");
 }
 else if (x ==3)
  { printf( "    *    \n"
  "   ***   \n"
   "  *****  \n"
   "    *    \n"
   "    *    \n"
   "    *    \n"
   "    *    \n"
   "    *    \n"
   "    *    \n");
   }
   else if (x==4)
   {printf ("    *    \n"
   "   * *    \n"
   "  *   *   \n"
   " *     *  \n"
   "*       * \n"
   " *     *  \n"
   "  *   *   \n"
   "   * *    \n"
   "    *    \n");}

}
printf("The end\n");
system("pause");
return 0;
}
4

2 回答 2

1
int main ()
{      
     int value=0;

     while(value != 9)
     {
         printf ("Enter your choice: ");
         scanf ("%d",&value);

         if (value == 1) 
         {    
             printf ("Oval");
         }

         else if (value == 2)
         {
             printf ("Rectangle");
         }       
    }

    return 0;
}
于 2013-11-12T08:19:19.973 回答
0

尝试这个:

int input = 0;

while(1) {
    scanf("%d", &input);

    switch(input) {
        case 9:
            break;

        // do your thing
    }
}
于 2013-11-12T08:17:12.560 回答