Skip to content
View in the app

A better way to browse. Learn more.

MSFN

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

newbie c++

Featured Replies

hi can you guys help me with my c++ im kinda newbie i dontknow why my program wont let me type in a response like yes and do what i want it to do and no so if you guys could fix it up for me please i would very much apprecieate it thanks heres the code

/*

My program about something just havent figured it out

yet

*/

#include <iostream>

#include <stdio.h>

using namespace std;

char c;

main()

{

cout << " Type in yes or no: \n";

repeat:

cin >> c;

if ( c = 'yes' )

{

cout << " Good Job!! :D !! ";

}

if( c = 'no' )

{

goto end;

}

else

cout << " Sorry That is not a correct response : \n";

goto repeat;

end:

return 0;

}


Wow, THIS really is code i will remember a long time :)

There are so many mistakes, i don´t know where to start, so i won´t start ;)

...label, goto, void main()...

Ok, so here comes a working one:

#include <iostream>
#include <string>

using namespace std;

int main()
{
  string strInput;
  bool bValidInput = false;

  cout << "Type in yes or no:" << endl;

  while (!bValidInput)
  {
     cin >> strInput;
     
     if ( strInput == "yes" )
     {
        cout << "You typed \"yes\"" << endl;
        bValidInput = true;
     }
     else if( strInput == "no" )
     {
        cout << "You typed \"no\"" << endl;
        bValidInput = true;
     }
     else
     {
        cout << "No correct input" << endl;
     }
  }

  return 0;
}

I know, it´s also not the best looking, but it think it´s ok for learning purposes.

The biggest advantage is, that it uses the "string" class to store and compare strings.

If you have more explicit questions, just ask.

so far.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.