Prompt the user for a line of text. Output that line in all capitals. Leave non-
ID: 3575353 • Letter: P
Question
Prompt the user for a line of text. Output that line in all capitals. Leave non-alphabetic characters untouched.
My code does not capitalize one sentence in the output.
My code:
#include <iostream>
#include<string>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main()
{
char name[39];
cout <<"Enter a line of text" << endl;
int i = 0;
gets(name);
while (name[i] != '')
{
if (name[i] >=97 && name[i] <= 122)
name[i] -=32;
++i;
}
puts(name);
return 0;
}
Output:
Required output Enter a line of text n THIS IS ANOTHER TEST. An Standard input Computer programming is the number 1 job Required output Enter a line of text n COMPUTERPROGRAMMING IS THE NUMBER 1 JoB!Nn Standard Input yes Required output Enter a line of text n YESAnl Your Program's output Enter a line of text n THIS IS ANOTHER TEST. Test Case 3 Failed Your Program's output Enter a line of text n Computer programming is the number 1 job n Test Case 4 Passed! Your Program's output Enter a line of text n YES AnExplanation / Answer
// C++ code
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main()
{
string sentence;
cout <<"Enter a line of text" << endl;
int i = 0;
// gets and puts usage should be avoided
getline(cin,sentence);
while (sentence[i] != '')
{
// convert lower case to uppercase
if (sentence[i] >=97 && sentence[i] <= 122)
sentence[i] -=32;
++i;
}
cout <<sentence << endl;
return 0;
}
/*
output:
Enter a line of text
Computer programming is the number 1 job!
COMPUTER PROGRAMMING IS THE NUMBER 1 JOB!
Enter a line of text
this is another test.
THIS IS ANOTHER TEST.
Enter a line of text
yEs
YES
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.