(C) Integer Calculator capable of Cancel and Quit -


I am quite new to coding and I should program an integer calculator. I have been installed it yet, but at any time need to quit the program by typing the words starting with "q", I should also be able to cancel the program, i.e. any starting from "c" Start a new calculation by typing the word. The code is

 include   

Here your program is edited according to your needs in the comments in the code explained everything new Gone:

  #include & lt; Stdio.h & gt; # Include & lt; Stdlib.h & gt; // Do not forget before joining! Int main () {char ch = NULL; To run 'Q' or 'c', // character {int x = 0; Int y = 0; Int r = 0; Four o; Printf ("***** Integer Calculator ***** \ n \ n \ n"); Printf ("Enter X:"); Scanf ("% d", & amp; x); Printf ("enter y:"); Scanf ("% d", & amp; y); Printf ("% d% d \ n", x, y); Printf ("+ - * / %%:"); Scanf ("% c", & amp; o); If o is a four as //% c no (o == '+') r = x + y; And if (o == '-') r = x-y; And if (o == '*') r = x * y; And if (o == '/') {if (x == 0 & amp; y == 0) {printf ("UNDEFINED \ n"); } And if (y == 0) {printf ("Error: DIVISION BY ZERO \ n"); } And {R = X / Y; }} And if (o == '%') r = x% y; Else {printf ("operator error! Try again: \ n"); } Printf ("Operation:% c \ n", o); Printf ("RESULT:% d \ n \ n \ n", r); While (1) // endless loop {printf ("once again enter 'a' to calculate and q to exit); scanf ("% c ", & amp; ch); if (f == 'C' || CC == 'q') // If there is an input C or Q break; // Break out of the infinite loop // If the input is not c or q printf ("Invalid option. Try again. \ N "); // print it and continue the infinite loop // ch now is either c or q when execution arrives here} while ch (ch! = 'Q'); // until loop is not q Returns 0;}  

Comments