using namespace std;
//int main ()
int tolower (int c);
int toupper (int c);
{
char a,b,c;
cin >> a;
b = toupper (a);
c = tolower (a);
char str 2 [100];
cout << "Please type a sentence \n";
cin >> getline (str2,100);
cout << "capitalize firt character in each sentence";
cin >> Please type a sentence ;
system("pause");
return 0;
}
Dude, timmmyyy was showing you pseudo-code. It's just an example of the program structure. Where he wrote "CAPITALIZE!" YOU are supposed to put in code that does the actual work. C++ is not magic!
Do you know how to read a string of text from the user?
Do you know how to write a for loop?
Do you know how to convert a single character to upper case?
Do you know how to access individual characters in a string?
If the answer to any of those questions is "no", then you need to spend some time learning and understanding the basic concepts (That means you need to take some time out to read your notes/book(s) and tutorials, and you need to try writing simpler programs which you can understand).
You won't learn by stabbing in the dark when you're already missing some of the basics, so save yourself the wasted time and frustration by making sure you understand the basics first.
#include <iostream>
#include <string>
//This function accepts any string and Capitolizes the first character
string Capitolize(string input)
{
if (input[0] <= 'z' && output[0] >= 'a')
input[0] -= 0x20; //Convert to upper, ref: http://www.asciitable.com/return input;
}
usingnamespace std;
int main ()
{
string Sentence;
cout << "Please type a sentence \n";
getline(cin,Sentence); // Using getline so we can include whitespaces
cout<<Capitolize(Sentence); // cout the result of a capitolized sentence
system("pause");
return 0;
}
#include <iostream>
#include <cctype>
#include <cstring>
constint MAX_LENGTH = 500;
int main()
{
char sentence[MAX_LENGTH];
bool cap_it = true;
std::cout << "Write a sentence and the first letter of each word will be capitalized for you.\n";
std::cin.getline(sentence, MAX_LENGTH);
for (int i = 0; i < strlen(sentence); i++)
{
if (isalpha(sentence[i]) && cap_it == true)
{
sentence[i] = toupper(sentence[i]);
cap_it = false;
}
elseif (isspace (sentence[i]))
cap_it = true;
}
std::cout << std::endl << sentence << std::endl;
return 0;
}
How exactly do you think you're helping anybody by spoon-feeding somebody a solution to their homework? The point of these forums is to assist beginners in learning - it's not helpful at all to hand out code to someone who either lacks understanding (And therefore isn't going to get that understanding from just copying a bit of code from the internet) or is plainly too lazy to spend their own time studying and practising.
In fact it's entirely counter-productive; not least because it encourages posters to keep on "begging" others to do their work for them without making the effort to learn anything themselves, and because the next time the poster comes across a more difficult problem which they can't solve, they'll be even more stuck since they've already got gaps in their understanding from when they missed out the last time. Please don't do it again.