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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -