0

Updated: When I Enter 1 it shows, How are you? and then directly bye skipping the the second if statement and directly goes to else. While after displaying how are you it should get the input from user and and the respond according to the if else statement. In this code I tried to use getline() for getting full sentence as input from user and show results. It's a very basic program. I was trying to make small interactive platform.

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

int main()
{
    int a;
    string b;
    string b1 = "I am fine";
    std::cout << "Hello, Enter 1 to continue...." << std::endl;
    std::cin >> a;
    if(a==1){
        std::cout << "How are you?" << std::endl;
        getline(std:: cin, b);
    }else{
        cout<<endl;
    }
    int c;
    if(b == b1){
        std::cout << "Gald to know that, press 2 to continue..." << std::endl;
        cin>>c;
    }else{
        std::cout<< "Bye" <<endl;
    }

    return 0;
}
Anmol
  • 1
  • 2
  • Please provide an example run of the program: What did you enter, what did the program show, and indicate when would you would have expected a different result – codeling Dec 21 '21 at 13:49
  • Syntax error ? What is the error? – 463035818_is_not_an_ai Dec 21 '21 at 13:50
  • Can you share the error you're getting? – Mureinik Dec 21 '21 at 13:50
  • If you want to read a whole line instead of single words, check e.g. here: https://stackoverflow.com/questions/5455802/how-to-read-a-complete-line-from-the-user-using-cin – codeling Dec 21 '21 at 13:51
  • When I Enter 1 it shows, How are you? and then directly bye skipping the the second if statement and directly goes to else. While after displaying how are you it should get the input from user and and the respond according to the if else statement. – Anmol Dec 21 '21 at 14:00

0 Answers0