CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Threaded View

  1. #1
    Join Date
    May 2008
    Posts
    12

    Second part of my program repeats and...

    Why? I added a function to test things and it's now repeating once and automatically assumes I entered something other than y, or n.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int squared(int s)
    {
     return s * 2;
    }
    
    
    int main()
    {
     top:
     system("CLS");
     
     cout << "What integer do you want squared? ";
     int x;
     cin >> x;
     cout << squared(x) << endl;
    
     string quitKey = "y";
     do
     {
      topOfLoop:
      cout << "Do you wish to quit? y/n ";
      getline(cin, quitKey);
      if (quitKey == "y") return 1;
      if (quitKey == "n") goto top;
      else
          cout << "What? ";
          goto topOfLoop;
     } while (quitKey != "y");
    
     return 0;
    }
    Last edited by Artitatt; June 11th, 2008 at 01:03 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured