c - How might I compare this variable so that I can use it in a switch statement? -


I just want to allow string or integer input, but I can not find it, this is what I have Is yet ..

  #include & lt; String.h & gt; # Include & lt; Stdio.h & gt; # Include & lt; Limits.h & gt; # Include & lt; Ctype.h & gt; # Include & lt; Stdlib.h & gt; #define maxL 9182 int main () {char menuOption; Four CMDs [10]; // The functions of the board are used in the float circle () {float no; Float calflot; Printf ("\ n \ nYou have selected a circle! \ N \ n"); Printf ("Enter value between 1.00 and 1000.00" :); Scanf ("% f% * c", & amp; calcflo); Printf ("You have entered% F \ n", Calphlot); Numbers = 2 * Calculus * 3.14159; Printf ("The circumference of your circle is:% f \ n \ n \ n", numbers); } Float area () {float area; Float calcefire; Printf ("\ n \ nYou have selected an area! \ N \ n"); Printf ("Enter value between 10.5 and 1024.00"); Scanf ("% ch% * c", & amp; calcSphere); Printf ("You have entered% F \ n", calcefware); Spherical = (4/3) * calcip spray * calcefire * calcefware * 3.14159; Printf ("Your value has an area volume:% .2f \ n \ n \ n", field); } Four probe input (four input) {if ((strcmp (input, "0") == 0) || (strump (input, "zero") == 0)) {return 0; }} // Create the end of the tasks // Show the menu and get the direct input for the right function I \ N "" (3) Shuffle \ n "" (4) \ n ") Skip; Printf (" Select: "Scanf" ("% c", CMD); switch (checkinput (toller (CMD)) {case 0: circle (break); case 1: area (break);}} /   

I either type people or zero to scanf to reduce the user error, thanks!

Change your checkInput function like this

  Integer probe input (four * input) {int i = 0; while (i & Lt; strlen (input)) input [i] = toller (input [i]); if ((SRCMP (input, "0") == 0) || (SRCMP (input, "zero") == 0 } Return {0;} and if ((SRCMP (Input, "1") == 0) || (SRCMP (Input, "one") == 0)) {return1;} return 4; // Exit Option}   

and make a call in your main

  switch (check input (CMD)) {case 0: circle ( ); break; Case 1: Area (); break; }   

You are accepting a string in the variable cmd . This should be done by the four CMDs [10]; Announce as a character array such as

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -