Need help figuring out why my code doesn\'t work. I have: void lowerNoPunctuatio
ID: 3871725 • Letter: N
Question
Need help figuring out why my code doesn't work. I have:
void lowerNoPunctuation(string str, string p){
int i,j;
for(i=0;i<p.length();i++){
int b = str.length();
for(j=0;j<b;j++){
if(str[j] == p[i]) str.erase(j,1);
b = str.length()
}
}
for(i=0;i<str.length();i++) if(isupper(str[i])) str[i] = (char)((int)str[i]+32);
}
I keep getting:
When comparing sentences we are often not interested in differences in case (UPPERCASE vs lowercase) or punctuation. For this problem, you will be writing a function that takes two string parameters- sentence and punctuation and returns the same string in lowercase (remember the built-in tolower function) and with givern punctuation removed. You must use nested loops. The built lowerNoPunctuation returns a string and takes a two strings as parameters string lowerNoPunctuation(string str, string punch) //Your code here Example Output: string str-"Hello, my name is Inigo Montoya. You killed my father. Prepare to die!" string punct - ".,!? string newStr = lowerN°Punctuation(str, punct) coutExplanation / Answer
//use the below program to convert all to lowercase and remove the punctuations.
//your above error is related to the headers.
#include <string>
#include <iostream>
#include <cctype>
int main() {
std::string str = "this. is my string. it's here.";
for (int i = 0, len = str.size(); i < len; i++)
{
if (ispunct(str[i]))
{
str.erase(i--, 1);
len = str.size();
}
}
for(i=0;i<=strlen(str);i++)
{
if(str[i]>=65 && str[i]<=92)
{
str[i]=str[i]+32;
}
}
std::cout << str;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.