Hello im stuck at SUBTRACTION AND DIVITION AND I CANT FIGURE OUT WHAT CODE to use because when I try to subtract 10 i inputed it then it will loop since the while condition is not meet which it needs to be negative to terminate the loop and i inputed 2 for the second number then loop again then i putted -number which lead to terminate loop and subtract all the number but the result is -12 its always wrong in every number cant figure out why Please help Also with divition, only my addition is working havent started the divition cuz i cant figure out how
#include <iostream> using namespace std; int amt2, total; double subNumbers(); double amt=1; double number=0; int main() { int chc=0; int amt = 0; int amt2 = 1; cout << "Welcome again User!\n"; cout << "______________________________________________________________\n" << endl; cout << "Mathematical Operations(Improved):\n\n"; cout << "\t[1]-Addition" << endl; cout << "\t[2]-Subtraction" << endl; cout << "\t[3]-Multiplication" << endl; cout << "\t[4]-Division\n" << endl; cout << "______________________________________________________________\n" << endl; cout << "Type the number corresponding to your chosen operation: "; cin >> chc; ``` switch (chc) { case 1: ``` system ("cls"); cout << "\n\n\tOperation chosen: Addition"; cout << "\n______________________________________________________________" << endl; cout << "\n\nInput positive numbers to use the operation and input a negative number to end the operation.\n\n"; cout << "Enter your number: ";` cin >> number; while (number >= 0) { // add all positive numbers amt += number; // take input again if the number is positive cout << "Enter another number: "; cin >> number; } // display the sum cout << "\nThe sum of all the numbers is: " << amt << endl; break; ``` case 2: system ("cls"); cout << "\n\n\tOperation chosen: Subtraction"; cout << "\n______________________________________________________________" << endl; cout << "\n\nInput positive numbers to use the operation and input a negative number to end the operation.\n\n"; do{ cout << "Enter your number: "; cin >> number; amt=number-number ; }while (number >= 0);// subtract all positive numbers // display the difference cout << "\nThe difference of all the numbers is: "<<amt; return 0; }} ``` enter code here
amthas when you doamt=number-number ;?number - numberis? What do you get if you subtract a number from itself?numberis a single variable -- that's all it is, and that's all it will be. So when you donumber-number, you are substracting the value innumberfrom the value innumber, giving you a result of 0.