Program to correct unwanted space and capitalization; but I don't want it to delete the first word
// Trying to run on Visual Studio
// EXAMPLE: THIS is a space TODAY.
// SHOULD BE: This is a space today.
// and end it with: Thank you for your time
NEVER MIND - I GOT IT TO RUN :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
int c=0, d=0, e=0, i=0;
string sentence;
cout << "Enter a string: " << endl;
getline(cin, sentence, '.');
char nextChar;
bool oneSpace = false;
for (int i = 0; i < sentence.length(); i++)
{
if (sentence[i] == ' ')
{
if (sentence[e] == '.')
{
break;
}
if (!oneSpace)
{
oneSpace = true;
}
else
{
sentence.erase(i, 1);
i = i - 1;
}
}
else
oneSpace = false;
}
for (int c = 0; c < sentence.length(); c++)
{
sentence[c] = tolower(sentence[c]);
d = 0;
sentence[d] = toupper(sentence[d]);
}
cout << sentence << "." << "\n\nThank you for using this program" << endl;
system("pause");
return 0;
}
|
Last edited on
Topic archived. No new replies allowed.