Subtraction in a while loop -


i new programing game. , when run problems can fix them quite little help. on has me stumped.

i attempting build basic calculator of sorts, , i'm using while loops it.

addition simple because had type: sum +=

however subtraction, multiplication, , division not easy. wondering if point me in right direction said before stumped.

here part of code reference:

    x = 0;      while(x < y){         if(operator == 1){          /*addition portion*/      x += 1;     printf("please enter number %d: ", x);     scanf("%lf", &a);          sum += a;}          else if(operator == 2){     /*subtracion portion*/     x += 1;     printf("please enter number %d: ", x);     scanf("%lf", &b);          sum += b - sum;}}               /*not working, fix, research*/      printf("\nthe sum of entered numbers = %.f\n\n", sum); 

you can use other operators -=, *=, , /= subtraction, multiplication, , division, respectively. example:

sum -= c; // equivalent "sum = sum - c;" sum *= d; // equivalent "sum = sum * d;" sum /= e; // equivalent "sum = sum / e;" 

(by way, can find big tables of operators in c , c++ in various places. might little overwhelming @ moment, they'll great reference later on!)


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -