mardi 30 novembre 2021

How can i solve this While Loop code? Is not repeat code [closed]

Hi I have an problem with my code. if i input on my variable again char N, code not repeat again, but if i input Y in again variable code return cout and finish.

#include <iostream>

using namespace std;

int main()
{
    char again = 'N';
    string firstName, lastName;
    while (again == 'n' || again == 'N') {
        cout << "Hello" << endl
             << "Enter You'r First Name: ";
        cin >> firstName;
        cout << "Enter you'r Last Name: ";
        cin >> lastName;
        cout << "You'r name is " << firstName << " " << lastName << endl;
        cout << "Right (Y/N): " << endl;
        cin >> again;
        if (again == 'y' || again == 'Y') {
            cout << "Have a nice day!";
        }
        return 0;
    }
}

Aucun commentaire:

Enregistrer un commentaire