Write a program that prompts the user to input a string and outputs the string in uppercase letters. (Use dynamic arrays to store the string.)
my code below:
/*
Your code from Chapter 8, exercise 5 is below.
Rewrite the following code to using dynamic arrays.
*/
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;
int main()
{
//char str[81];
//creating memory for str array of size 80 using dynamic memory allocation
char *str = new char[80];
int len;
int i;
cout << "Enter a string: ";
cin.get(str, 80);
cout << endl;
cout << "String in upper case letters is:"<< endl;
len = strlen(str);
//displaying each character in upper case letter
for (i = 0; i < len; i++)
cout << static_cast<char>(toupper(*(str+i)));
cout << endl;
return 0;
}
keeping getting it wrong need help not sure what im doing wrong
Input
11 Hello World Output Enter a string: 11 String in upper case letters is: 11 Hello World |
|
Test Case Incomplete To Upper Test 2 Input 14 I love to code Output Enter a string: 14 String in upper case letters is: 14 I love to code |
|
Below is the code which I wrote:
Quite similar to what you've written but used different way for taking string input and typecasting integer to character. That's working as expected.
Below is the output:
PS: Comment for more discussion
Get Answers For Free
Most questions answered within 1 hours.