Browse Source

first commit

unknown 1 month ago
parent
commit
3452ec7216
1 changed files with 65 additions and 38 deletions
  1. 65 38
      InControl/Main.c

+ 65 - 38
InControl/Main.c

@@ -36,45 +36,56 @@ void inputData(int a,int* f, float* a1, float* b1, float* c1, float* a2, float*
     case 1:
         for (;;)
         {
-            printf("Ââåäèòå a: ");
-            if (fgets(buf, sizeof buf, stdin) == NULL) {
-                printf("Input closed\n");
-                break;
-            }
-            int n;
-            if (sscanf_s(buf, "%f %n", a1, &n) == 1 && buf[n] == '\0')
+            for (;;)
             {
-                break;
+                printf("\nÂâåäèòå a: ");
+                if (fgets(buf, sizeof buf, stdin) == NULL) {
+                    printf("Input closed\n");
+                    break;
+                }
+                int n;
+                if (sscanf_s(buf, "%f %n", a1, &n) == 1 && buf[n] == '\0')
+                {
+                    break;
+                }
+                printf("<%s> ýòî íå 1 ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
             }
-            printf("<%s> ýòî íå 1 ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
-        }
-        for (;;)
-        {
-            printf("Ââåäèòå b: ");
-            if (fgets(buf, sizeof buf, stdin) == NULL) {
-                printf("Input closed\n");
-                break;
+            for (;;)
+            {
+                printf("Ââåäèòå b: ");
+                if (fgets(buf, sizeof buf, stdin) == NULL) {
+                    printf("Input closed\n");
+                    break;
+                }
+                int n;
+                if (sscanf_s(buf, "%f %n", b1, &n) == 1 && buf[n] == '\0')
+                {
+                    break;
+                }
+                printf("<%s> ýòî íå 1 ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
             }
-            int n;
-            if (sscanf_s(buf, "%f %n", b1, &n) == 1 && buf[n] == '\0')
+            for (;;)
             {
-                break;
+                printf("Ââåäèòå c: ");
+                if (fgets(buf, sizeof buf, stdin) == NULL) {
+                    printf("Input closed\n");
+                    break;
+                }
+                int n;
+                if (sscanf_s(buf, "%f %n", c1, &n) == 1 && buf[n] == '\0')
+                {
+                    break;
+                }
+                printf("<%s> ýòî íå 1 ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
             }
-            printf("<%s> ýòî íå 1 ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
-        }
-        for (;;)
-        {
-            printf("Ââåäèòå c: ");
-            if (fgets(buf, sizeof buf, stdin) == NULL) {
-                printf("Input closed\n");
-                break;
+            if (*a1 == 0 && *b1 == 0)
+            {
+                printf("Èç ýòèõ ÷èñåë óðàâíåíèå íå ïîëó÷èòüñÿ, ïîïðîáóéòå åùå ðàç", buf);
             }
-            int n;
-            if (sscanf_s(buf, "%f %n", c1, &n) == 1 && buf[n] == '\0')
+            else
             {
                 break;
             }
-            printf("<%s> ýòî íå 1 ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
         }
         break;
     case 2:
@@ -164,19 +175,31 @@ void inputData(int a,int* f, float* a1, float* b1, float* c1, float* a2, float*
         }
         break;
     case 3:
+
         for (;;)
         {
-            printf("Ââåäèòå a: ");
-            if (fgets(buf, sizeof buf, stdin) == NULL) {
-                printf("Input closed\n");
-                break;
+            for (;;)
+            {
+                printf("Ââåäèòå a: ");
+                if (fgets(buf, sizeof buf, stdin) == NULL) {
+                    printf("Input closed\n");
+                    break;
+                }
+                int n;
+                if (sscanf_s(buf, "%d %n", f, &n) == 1 && buf[n] == '\0')
+                {
+                    break;
+                }
+                printf("<%s> ýòî íå öåëîå ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
             }
-            int n;
-            if (sscanf_s(buf, "%d %n", f, &n) == 1 && buf[n] == '\0')
+            if (*f < 0)
+            {
+                printf("×èñëî äîëæíî áûòü ïîëîæèòåëüíûì, ïîïðîáóé åùå ðàç\n");
+            }
+            else
             {
                 break;
             }
-            printf("<%s> ýòî íå öåëîå ÷èñëî. Ïîïðîáóé åùå ðàç\n", buf);
         }
         break;
     }
@@ -210,7 +233,11 @@ void GetData(int a,int f, float x1, float x2)
         }
         break;
     case 3:
-        printf("Ôàêòîðèàëà ðàâåí %d", f);
+        if (f == 0)
+        {
+            printf("Ôàêòîðèàëà ðàâåí 1", f);
+        }
+        else printf("Ôàêòîðèàëà ðàâåí %d", f);
         break;
     }
 }