int main() { string str; int count_star = 0; int count_percent = 0;
cout << "Enter a string: "; getline(cin, str); for (int i = 0; i < str.length(); i++) { if (str[i] == '*' || str[i] == '%') { if (str[i] == '*') { count_star++; } else { count_percent++; } } } if (count_star > count_percent) { cout << "There are more '*' than '%' in the string by " << count_star - count_percent << " characters." << endl; } else if (count_percent > count_star) { cout << "There are more '%' than '*' in the string by " << count_percent - count_star << " characters." << endl; } else { cout << "The number of '*' and '%' characters is equal in the string." << endl; } return 0;
using namespace std;
int main() {
cout << "Enter a string: ";string str;
int count_star = 0;
int count_percent = 0;
getline(cin, str);
for (int i = 0; i < str.length(); i++) {
if (str[i] == '*' || str[i] == '%') {
if (str[i] == '*') {
count_star++;
} else {
count_percent++;
}
}
}
if (count_star > count_percent) {
cout << "There are more '*' than '%' in the string by " << count_star - count_percent << " characters." << endl;
} else if (count_percent > count_star) {
cout << "There are more '%' than '*' in the string by " << count_percent - count_star << " characters." << endl;
} else {
cout << "The number of '*' and '%' characters is equal in the string." << endl;
}
return 0;
}