if you are assigning a value to a character variable in a loop, you can do this:
-sharpinclude <iostream>
int main()
{
using namespace std;
char ch;
cout << "Type, and I shall repeat.\n";
cin.get(ch);
while(ch != ".")
{
if(ch == "\n")
cout << ch;
else
cout << PPch;
cin.get(ch);
}
cout << "\nPlease excuse the slight confusion.\n";
return 0;
}
The effect of this code is that the user can enter characters until they enter"." So far, no matter enter the space or enter in the middle, you can continue. what should I do if I want to change the above character variable to a character array and use similar simple code?
I wrote it myself, but I thought it was a little complicated and used a nested loop. How can it be easier?
-sharpinclude <iostream>
const int Asize = 20;
int main()
{
using namespace std;
char line[Asize];
cout << "Type, and I shall repeat.\n";
int count = 0;
while(count == 0)
{
cin.getline(line, Asize);
for(int i = 0; line[i] != "\0"; iPP)
{
if(line[i] == "\n")
cout << line[i];
else
{
if(line[i] == ".")
countPP;
cout << PPline[i];
}
}
}
cout << "\nPlease excuse the slight confusion.\n";
return 0;
}