0

can someone help me, my code won't compile.

#include <iostream>
#include <string>
using namespace std;

int main()
{

int hi, lo, mid;
bool found;
char status, reply;

do
{
     cout << "Think of a number between 0 and 1000" << endl;
     cout << " Write it down, I will guess it" << endl;
     hi = 1001;
     lo = 0;

     found = flase;
     while((hi >= lo) && (!found))
    {
               mid = (hi + lo) /2;
               cout << "is" << mid << "H) igh, L) ow, or C) orrect?"
               << endl;
               cin >> status;
               switch (toupper(status))
               {
                      case 'H':
                           hi = mid;
                           break;
                           case 'L':
                           lo = mid
                           break;
                           case 'C':
                                found = true;
                                break;
                                default:
                                        cout << "Invalid response!" << endl;
                                        }
                                        }

               if(hi < lo)
               cout << "You cheated" << endl;
               else
               cout << "Your number is " << mid << endl;
               cout << endl;
               cout << "Do you want to go again? Y or N" << endl;
               cin >> reply;
               }while(toupper(reply) == 'Y';
               return 0;
}
3
Contributors
3
Replies
4
Views
4 Years
Discussion Span
Last Post by wids101
0

what are the eror(s)? Line up the { and } so that they are in the same column on the screen. Same for case statements, they should not be indented like they are shown in your post. Something like this example. Note: Your post will keep the spacing if you replace tabs with spaces. IDEs usually have an option to do that for you.

int main()
{
   if( something )
   {
       switch(x)
       {
          case 1:
             // blabla
             break;
          case 2:
            // blabla
            break;
          default:
            // blabla
            break;
        }
    }
}

Edited by Ancient Dragon

0

Fix:
line 19, flase should be false
line 32, should be lo = mid;
line 49, should be }while(toupper(reply) == 'Y');

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.