(Data processing) a. Write a C++ program that stops reading a line of text when
ID: 3694653 • Letter: #
Question
(Data processing) a. Write a C++ program that stops reading a line of text when a period is entered and displays the sentence with correct spacing and capitalization. For this program, correct spacing means only one space between words, and all letters should be lowercase, except the first letter. For example, if the user enters the text i am going to Go TO THe moVies., the displayed sentence should be I am going to go to the movies.
b. Determine what characters, if any, aren’t displayed correctly by the program you created.
THIS IS WHAT I HAVE SO FAR, I cant get my code to fix the spacing Please help
#include<iostream>
#include<string>
#include<cmath>
#include<iomanip>
using namespace std;
int main()
{
string string1;
int letter;
cout<<"Please enter the string: " <<endl;
getline(cin, string1);
letter= string1.length();
int loopcount=0;
while(string1.at(loopcount)!='.')
loopcount++;
//To erase the extra function after.
string1.erase(loopcount+1, letter-loopcount-1);
letter=loopcount+1;
string1.at(0)=toupper(string1.at(0));
for (int loopcount = 1; loopcount < letter; loopcount++)
{
string1.at(loopcount) = tolower(string1.at(loopcount));
}
cout<<" The correct string is: "<<setw(1) <<string1<<endl;
system("PAUSE");
return 0;
}
Explanation / Answer
there is problem in getline(). please check the syntax
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.