-1

Would someone mind pointing out to me, as it has been quite a while since I have compiled any C++ code, the reason that the following code is generating an error on my attempt to build it. It is an attempt to build a very basic, entry level, Win32 Console application and the IDE has been configured to expect as much. I thank, in advance, whoever might take the time to point out my oversite. The code is as follows:

#include "stdafx.h"
#include <iostream>
using namespace std;


bool accept()

{
    int tries = 1;
    while (tries < 4) {
       cout << "Do you want to proceed (y or n)?\n";
       char answer = 0;
       cin >> answer;

       switch (answer) {
        case 'y':
            return true;
        case 'n':
            return false;
                default: 
                cout << "Sorry, I don't understand that.\n";
                tries = tries ++;
       }

       cout << "I'll take that for a no.\n";
       return false;

       system("pause");
   }

The error message is:

1>c:\users\court\documents\visual studio 2010\projects\cpp1\cpp1\cpp1.cpp(37): fatal error C1075: end of file found before the left brace '{' at 'c:\users\court\documents\visual studio 2010\projects\cpp1\cpp1\cpp1.cpp(10)' was matched The error is as follows:

Again, thank you, in advance for any assistance I might be afforded.

taocp
  • 22,732
  • 9
  • 48
  • 60
court
  • 53
  • 10
  • 2
    what is the error or behaviour witnessed? – hmjd May 21 '13 at 13:45
  • Thank you for your response, just a moment and I will post the error. – court May 21 '13 at 13:47
  • 1
    unbalanced `{` ? 3 `{` and 2 `}`, unless you didn't include the end brace – SGM1 May 21 '13 at 13:49
  • @count, hmm... you missed a '}'. count it. – treehouse May 21 '13 at 13:49
  • With proper indentation you can see that you're missing the closing bracket } for the method. – Yochai Timmer May 21 '13 at 13:49
  • @court Pretty sure you want the brace after the switch statement. Based on the `cout` statements logic. – SGM1 May 21 '13 at 13:51
  • The IDE will format your code for you if you ask it nicely (I think the command is in the Edit menu). That would have made it easier to find the missing `}`. – Keith Thompson May 21 '13 at 15:06
  • @court in addition to the missing `}` and the indentation issues people brought up, two additional comments: First use `std::endl` (e.g. `cout << "Hello" << endl;`) and not `\n` to indicate a new line. Secondly please [don't use `system("pause")`](http://stackoverflow.com/questions/1107705/systempause-why-is-it-wrong). – Nik Bougalis May 21 '13 at 17:56

2 Answers2

3

Looks like you're missing a closing brace after your switch statement. It's isn't obvious due to the missing indent after 'while'.

Erik Post
  • 836
  • 7
  • 12
1

Hit Ctrl+A. Then hit Ctrl+K and Ctrl+F. Then go to the extensions and updates manager and install Indent Guides. Then you'll see you're missing a brace.

derpface
  • 1,533
  • 1
  • 9
  • 19