Predeclared variable works, so if one comments out the cin statement, it goes through until the end.
when using CIN to capture the input, it terminates at the first space.
the exercise says not to use CLR, but c++/cli.
I still can't figure out why the user input string is terminating, but the declared string is not.
I am using vc++ express 2008, second exercise from Hortons Learn VC++ 2010
chapter 4.
Declare a character array, and initialize it to a suitable string. Use a loop to change every other character to uppercase. HINT. in ASCII character set, Uppercase is 32 less than lowercase counterpart.
I feel stupid, like I should be getting this already.
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 29 30 31 32 33 34 35 36
|
#include<iostream>
#include<iomanip>
using std::cout;
using std::cin;
using std::setw;
using std::endl;
int main()
{
char ss_string[] = "Why does this work, but CIN >> will not";
short ii_count = 0;
cout << "Input some text, to convert every other letter to uppercase.";
cout << endl;
cin >> ss_string;
cout << endl;
do
{
if(ss_string[ii_count] >= 'a' && ss_string[ii_count]<='z')
{
if(ss_string[ii_count - 1] >= 'A' && ss_string[ii_count - 1]<='Z')
{
//empty struct to skip the code if the prior letter is Uppercase
}else {ss_string[ii_count] = (ss_string[ii_count] - 32);};
}
ii_count ++;
}while(ss_string[ii_count] != '\0');
cout << ss_string;
cout <<endl;
return 0;
}
|