Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why is the output not what I want it to be

–2 votes
asked May 2, 2020 by Ivana Ogunlaja (640 points)
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string subject;
    cout << "What is your favourite subject";
    cin >> subject;
    cout << "Nice",subject, "is a good subject";
    return 0;
}

output

What is your favourite subject? input maths

output Nice

1 Answer

+2 votes
answered May 2, 2020 by LiOS (6,420 points)
selected May 3, 2020 by Ivana Ogunlaja
 
Best answer
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string subject;
    cout << "What is your favourite subject";
    cin >> subject;
    cout << "Nice " << subject << " is a good subject";
    return 0;
}
commented May 2, 2020 by Vignesh Waran (100 points)
the answer for :
       What is your favourite subject Nice is a good subject
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...