#include <iostream>
#include <string>
int getPositiveInt()
{
int number;
do
{
cout << "Please enter a positive number" << endl;
cin >> number;
}
while(number < 0);
return number;
}
void printText(int number, string textMessage)
{
for(int i = 0; i < number; i++)
{
cout << textMessage << endl;
}
}
using namespace std;
int main()
{
int number = getPositiveInt();
cout << "The positive value that was entered is " << number << endl;
string textMessage;
cout << "Please enter a message." << endl;
getline(cin, textMessage, '\n');
printText(number, textMessage);
return 0;
}
So this program asks the user for a number, then a message then prints the message that number of times. The problem is here getline(cin, textMessage, '\n'); I want the message to include the whitespace in between words (so a whole sentence), and only end when the user hits enter but the way I have it results in not even being able to enter a message because it sees the initial whitespace and thinks the message input is done.