I am trying to write a C ++ program where you can choose which operation you want to create and Then calculate the quantity result of numbers and I want to use a getchar
function, but I can not understand how can you create intro so that it behaves like a variable?
#include & lt; Iostream & gt; # Include & lt; Stdio.h & gt; using namespace std; Int main () {/ * char a_char; A_char = getchar (); Cout & lt; & Lt; A_char; * / Int opcode; Int a, b; Full result; Printf ("Program for Addition, Subtraction, Multiplication and Partition \ n"); Printf ("Enter your option: 1 - add, 2 - sub, 3 - root, 4 - partition:"); Scanf ("% d", and opcode); Printf ("Enter first number:"); Scanf ("% d", & amp; one); Printf ("Enter second number:"); Scanf ("% d", & amp; b); Switch (opcode) {case 1: result = A + b; Printf ("% d +% d =% d", a, b, result); break; Case 2: Result = A - B; Printf ("% d -% d =% d", a, b, result); break; Case 3: Results = a * b; Printf ("% d *% d =% d", a, b, result); break; Case 4: Results = A / B; Printf ("% d /% d =% d \ n% d %%% d =% d", a, b, result, a, b, a% b); break; }}
Assuming you get the operation code through the getchar Input
, something like this will appear:
opcode = getchar ();
And then in your switch
you can find values in singular quotations:
case '1': .. .. case '2': .... and so on
Comments
Post a Comment