Write a program to capitalize the 1st char of each word in a sentence

eg"Return An Integer That Is The Start Position Of The First Occurrence Of The String"
Last edited on
int main () {
bool doItYourself = true;
while (doItYourself) { cout<<"i'm not your slave"<<endl; }
return EXIT_SUCCESS;
}
cout << implode(transform(explode(str,' '),capitalizeFirstChar),' ') << endl;
You might have to implement some of those functions yourself.
ok thanks will put my code n a min
#include <iostream>
#include <string>


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);


system("pause");
return 0;
}
#include <iostream>
#include <string>


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;
}


stil cant get it too work
You are doing it all wrong!

int main (){
cout << "Please type a sentence \n";
cin>>the cat is blue
CAPITALIZE!
cout<<sentence_capitalized
}

this should work + -
#include <iostream>
#include <string>


using namespace std;
int main ()
{
char 1st character;
cout << "Please type a sentence \n";
cin >> the cat is blue;

cout<<sentence_capitalized 1st char;




system("pause");
return 0;
}

I cant get it,im gett'n very sick of c++
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!
Well sro i still dont know what to do with it,
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.
From your earlier code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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;
}

using namespace 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;
}
Last edited on
Great code thanks,but it still won't work,capitalize undecleard and no string name coming up in the errors,it won't compile.
Read your textbook.
I let the text book in college and must hand this in first thing in the morning ok.
Any one out there that can give me a hand please
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
#include <iostream>
#include <cctype>
#include <cstring>

const int 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;
        }
        else
            if (isspace (sentence[i]))
                cap_it = true;
    }

    std::cout << std::endl << sentence << std::endl;

    return 0;
}


std::cin.get(); // add this code right below the cout statement if you need it to freeze the screen when program terminates.

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.
Last edited on
Topic archived. No new replies allowed.