OK, so on my program, whenever I enter in incorrect selection (when I am actually running it), it goes back to the main loop and continually loops! what's wrong with it? here's the code:

/*
  Copyright: 2008
  Author: Besktrap
  Date: 13/07/08 09:19
  Description: a short buggy calculator I made
*/

#include <iostream>
#include <windows.h>
using namespace std;
void setcolor(unsigned short color)                 //The function that you'll use to
{                                                   //set the colour
    HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hcon,color);
}
int main()
{
    system ("title Calculator");
    loop:
         system ("cls");
    setcolor (10);
    cout << "Menu\n\n";
    setcolor (7);
    cout << "1) Subtraction\n2) Multiplication\n3) Addition";
    cout << "\n4) Division...\n";
    int menu;
  cout << "\n\nYour selection: ";
  cin >> menu;
  if ( menu == 1) { // If "menu" equals 1...
       setcolor (12); //Set the color to red             
                     long int subnum1;
                     cout << "\nYour first number to subtract? ";
                     cin >> subnum1;
                     long int subnum2;
                     cout << "Your second number? ";
                     cin >> subnum2;
cout << "\nSubtracting " << subnum1 << " and " << subnum2 << " gives you a total of " << subnum1-subnum2 << "\n\n";
  cout << "[Press any key to continue]";
system ("pause >nul");
  goto loop;}
  if ( menu == 2) {
       setcolor (3);
       long int mul1;
            cout << "\nYour first number to multiply? ";
                cin >> mul1;
                long int mul2;
                cout << "Your second number? ";
                cin >> mul2;
cout << "\nMultiplying " << mul1 << " and " << mul2 << " gives you a total of " << mul1*mul2 << "\n\n";
cout << "[Press any key to continue]";
system ("pause >nul");
goto loop;}
                if ( menu == 3) {
                     setcolor (11);
                     long int num1;
                     cout << "\nYour first number to add? ";
                     cin >> num1;
                     long int num2;
                     cout << "\nYour second number? ";
                     cin >> num2;
                     cout << "\nAdding " << num1 << " and " << num2 << " gives you a total of " << num1+num2 << "\n\n";
                     cout << "[Press any key to continue]";
system ("pause >nul");
                     goto loop;}
                setcolor (7);
                if ( menu == 4) {
                     setcolor (9);
                     long int div1;
                     cout << "\nWhat number do you want to divide first? ";
                     cin >> div1;
                     long int div2;
                     cout << "\nYour second number? ";
                     cin >> div2;
                     cout << "\nDividing " << div1 << " by " << div2 << " gives you a 'rounded' total of " << div1/div2 << "\n\n";
                     cout << "[Press any key to continue]";
system ("pause >nul");
                     goto loop;}
                     else;
                     {
                         setcolor (6);
                         cout << "\nIcorrect selection...you will now be TERMINATED!!\n\n"; 
                     setcolor (7);
      system ("pause >nul");
      return 0;
      }
}

For starters, why are you using goto instead of a simple loop?

>it goes back to the main loop and continually loops!
It works for me. Please provide exact steps during execution to reproduce the problem.

This article has been dead for over six months. Start a new discussion instead.