Coverting a string into upper or lowercase
Need some help with a program I am rying to work.
I am trying to have a user input a string of characters, then count and compare the number of upper and lower case characters, then gie the option to change the string to all upper or all lower case letters, then display the changed string on the screen.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string x = "";
cout<<"Type your string: ";
cin>>x;
return 0;
}
I have been completely stuck on this for the past 2 days.
I was told by a friend that I needed to use ascii somehow? how?
that helped, one more thing
Ok I got the string to switch to upper or lower case, now what I need to do is insert a conditional statement asking if the user wants to change the case of the string after it reports the number of upper vs. lower case letters.
[code]
#include <cctype>
#include <iostream>
using namespace std;
using std::cout;
using std::endl;
int main(void)
{
char sent[] = "";
char* x=0;
int ucase=0;
int lcase=0;
cout << "Input Your String: " << sent << endl;
cin>> sent;
for(int i=0;i<strlen(sent);i++){
if((sent[i]>90)&&!(sent[i]==32)){
sent[i]=sent[i]-32;
lcase++;
}
if(sent[i]==32)ucase--;
}
ucase =strlen(sent)-lcase+ucase;
cout<<"There were "<<ucase<<" uppercase letters in the string"<<endl;
cout<<"There were "<<lcase<<" lowercase letters in the string"<<endl;
cout<<"Change the case of the string? (Y or N)" <<endl;
// does the conditional statemnt go here? or before the cout above?
for (char *iter = sent; *iter != '\0'; ++iter)
{
*iter = tolower(*iter);
++iter;
}
cout << "Here is your converted string: " << sent << endl;
return 0;
}