I am trying to complete an exercise from c++ primer 5th edition but keep i failing.
The exercise is:
Write a function that takes a reference to a string object as its parameter and that converts the contents of the string to uppercase. Use the toupper() function described in
Table 6.4. Write a program that uses a loop which allows you to test the function with
different input. A sample run might look like this:
Enter a string (q to quit) : go away
GO AWAY
Next string (q to quit) : good grief!
GOOD GRIEF!
Next string (q to quit) :
Bye.
please copy this source code and compile it and see how you can help me,
i would really appreciate some help.
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 37
|
#include <iostream>
#inclyde <cctype>
void lower_to_upper(char & Letters);
int main()
{
using namespace std;
char words;
cout << "Enter a string (press q to quit): ";
cin.get(words);
while(true)
{
if(words == 'q')
{
cout << "Bye.\n";
break;
}
else if(words != 'q')
{
lower_to_upper(words);
cout << "Next string (q to quit):";
}
cin.get(words);
}
return 0;
}
void lower_to_upper(char & Letters)
{
using namespace std;
cout << (char) toupper(Letters);
}
|
Here is my output:
Enter a string:code
C
ONext string (q to quit):DNext string (q to quit):ENext string (q to quit): |
As you can see the program has problems. If anyone knows what i mean please help me.