Hello all,
I am a noob to C++ and would appreciate any help that I can get. I am taking a beginner's course and got this assignment:
I have to take a users input (i.e. a sentence) and capitalize the first letter of the sentence and make sure each letter there after is lowercase.
hElLo wORld!! -----> Hello world!!
or even
hElLo wORld!! HOw Are yOU? -------> Hello world!! How are you?
This is my code thus far (which capitalizes everything):
#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;
//declare the functions used to convert the letters
void convert_to_upper(char *s);
int main()
{
char s[100];
//get input from the user
cout << "Please enter the sentence to be converted and press ENTER: " << endl;
cin.getline(s, 99);
//call the function to convert the users input
convert_to_upper(s);
//output the corrected sentence
cout << "Here is the corrected sentence: " << endl;
cout << s;
return 0;
}
//function to convert letters into lower case
void convert_to_upper(char *s)
{
int i;
int length = strlen(s);
for (i = 0; i < length; i++)
s[i] = toupper(s[i]);
}
Any and all help would be greatly appreciated? Thanks again.