lordzedd,bro.Solving this problem in this fashion is nothing more than a temporary solution.
you obviously don't grasp the most basic of concepts about programming
do what the people in page one told you to do.learn about loops,conditional statements,functions,all of the basics,then come back to this problem,and you will be able to solve it easily
//Chris Cochran
//COP2000.0M2
//Project 7
//This program will uppercase words and sentences
#include <iostream>
#include <cctype>
#include <string>
usingnamespace std;
class CharConverter
{
private:
string sentence;
int count;
public:
void uppercase(string sentence)
{
cout << "Type a sentence to see every letter be uppercased\n";
getline(cin,sentence);
for (int count = 0; count < sentence.length(); count ++)
{
sentence[count] = toupper(sentence[count]);
}
cout << sentence << endl;
}
void properWords(string sentence)
{
cout << "\nType a sentence to see the first letter of every word be uppercased\n";
cin.sync();
getline(cin,sentence);
sentence[ 0 ] = toupper(sentence[ 0 ]);
for (int count = 0; count < sentence.length(); count++)
{
if (sentence[count] == ' ')
{
count++;
sentence[count] = toupper(sentence[count]);
}
}
cout << sentence << endl;
}
};
int main()
{
CharConverter mainSentence;
string choice;
string sentence;
mainSentence.uppercase(sentence);
mainSentence.properWords(sentence);
do
{
cout << "Do you want to try again?(Y/N)\n";
cin >> choice;
if (choice != "y" && choice != "Y" && choice != "n" && choice != "N")
{
cout << "Please enter 'y' for yes or 'n' for no.\n";
cin >> choice;
}
}
while (choice == "y" || choice == "Y");
{
}
cout << "Have a good day!\n\n\n";
return 0;
}
Alright, I found out that I had to add sentence[ 0 ] = toupper(sentence[ 0 ]); right before the for statement because that makes it set the first letter of the string to uppercase. I had to take out the first sentence[count] = toupper(sentence[count]); statement because it was redundant and in the if statement, I had to make it == not =. So I got the properWords function completed. I just need help with the last loop that asks if the user wants to do it again. I'm having troubles trying to figure that out.
if (choice != "y" && choice != "Y" && choice != "n" && choice != "N") this should probably be a while loop not an if statement.
Also why is line 52 a string instead of character? Though if you make it a character you would put ' around characters instead of " since that is for a string so "n" would become 'n'.
int main()
{
CharConverter mainSentence;
string choice;
string sentence;
while (choice != "n" && choice != "N"){
mainSentence.uppercase(sentence);
mainSentence.properWords(sentence);
cout << "Do you want to try again?(Y/N)\n";
cin >> choice; // here is where its looping back to the function
while (choice != "y" && choice != "Y" && choice != "n" && choice != "N")
{
cout << "Please enter 'y' for yes or 'n' for no.\n";
cin >> choice;
}
}
cout << "Have a good day!\n\n\n";
return 0;
}
It works properly now. I just had to use some common sense lol