Hello
I have 2 functions that are just playing up. One is a function that takes in a string & should output the string backwards.
Problem: the syntax to insert a character into the string is wrong, I dont know the correct syntax.
The other is a function that takes in a string & converts each character to uppercase.
Problem: I dont know, as far as I can see, there is nothing wrong with the code, but it still outputs the string in a lowercase form, when it should be in uppercase
Any help would be greatly appreciated
Function 1:
string reverse(string s) {
int size = (int)s.length();
for (int i=0; i<size; i++) {
s[i].insert( s[size-1] ); // I get an error here???
s.erase(size);
}
return s;
Function 2:
string makeUpper(string s) {
for (int i=0; i<(int)s.length(); i++) {
if ( islower(s[i]) ) {
toupper(s[i]);
}
}
return s;
}
Code to call the functions:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int countUpper(string s); // Task 1
string reverse(string s); // Task 2
string makeUpper(string s); // Task 3
int main() {
string b = "abcde";
string c = "abcde";
cout << "String b reversed = " << reverse(b) << endl;
cout << "String b capitalised = " << makeUpper(c) << endl;
return 0;
}