Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include //Including for #include //Including for numeric_limits #include using namespace std; //Function for counting characters inside given string and returning the count int CountCharacters(char userChar,

#include //Including for #include //Including for numeric_limits #include using namespace std; //Function for counting characters inside given string and returning the count int CountCharacters(char userChar, string userString){ //Declaring i and count=0 int i,count=0; //For loop for iterating over each character of userString for(i=0;i //If the userChar is equal to the character at ith position then increment count value by 1 if(userChar==userString.at(i)){ count++; } } //Returning count value return count; }

int main() { //Declaring userChar variable char userChar; //Declaring characterCount variable int characterCount; //Declaring userString variable string userString; //flushing out enter key press to be stored into the //userString as a character, if enter key stored in userString then it will //not give desired output cin.ignore(numeric_limits::max(),' '); //Inputing string getline(cin, userString); //Calling character count function with two parameters userChar and userString characterCount = CountCharacters(userChar, userString); //Printing characterCount cout< return 0; }

Error on above question, please correct my error

main.cpp: In function int CountCharacters(char, std::string): main.cpp:15:13: warning: comparison of integer expressions of different signedness: int and std::__cxx11::basic_string::size_type {aka long unsigned int} [-Wsign-compare] 15 | for(i=0;i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions