When the code below is compiled and I choose 1 which is add and when my add function is finished my subtract function starts running even though I don't want it to, help me pleas.
Code:#include <iostream> int MenuAndMenuChoice(); double Add(); double Subtract(); int main() { //Function - MenuAndMenuChoice is called to print the menu and get the user's choice switch (MenuAndMenuChoice()) { //A descision is then made hear depending on what the user entered case 1: std::cout << "\nThe two numbers added together equal: " << Add(); case 2: std::cout << "\nThe second number subtracted from the first number equals: " << Subtract(); } std::cin.get(); return 0; } //Function MenuAndMenuChoice code starts here int MenuAndMenuChoice() { int MenuChoice; std::cout << "1.Add\n"; std::cout << "2.Subtract\n"; std::cout << "3.Multiply\n"; std::cout << "4.Divide\n"; std::cout << "5.Circle Area\n"; std::cout << "6.Circle Circumference\n"; std::cout << "7.Exit\n\n"; std::cout << "What would you like to do? "; std::cin >> MenuChoice; return MenuChoice; } //Function Add code starts here double Add() { double FirstNumber, SecondNumber, AddAnswer; std::cout << "\nWhat is the first number: "; std::cin >> FirstNumber; std::cin.ignore(80,'\n'); std::cout << "What is the second number: "; std::cin >> SecondNumber; std::cin.ignore(80,'\n'); AddAnswer = FirstNumber + SecondNumber; return AddAnswer; } //Function Subtract code starts here double Subtract() { double FirstNumber, SecondNumber, SubtractAnswer; std::cout << "\nWhat is the first number: "; std::cin >> FirstNumber; std::cin.ignore(80,'\n'); std::cout << "What number would you like to take away from the first number: "; std::cin >> SecondNumber; std::cin.ignore(80,'\n'); SubtractAnswer = FirstNumber - SecondNumber; return SubtractAnswer; }



LinkBack URL
About LinkBacks


