Instructions:
Given code:
#include <iostream>
#include <cstring>
using namespace std;
int main() {
// NOTE: Do not edit this
char location[100] = "CodeChumIsLoveAndProgrammingAsWellYey";
}
Example:
Enter the address: 1
Place at index 1 is o
#include <iostream>
#include <cstring>
#include <limits>
using namespace std;
void printIndex(char str[]) {
int i;
cout << "Enter the address: ";
cin >> i;
while (!std::cin || i < 0 || i >= strlen(&str[0])) {
cout << "Error! Wrong address!\nEnter the address: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cin >> i;
}
cout << "Place at index " << i << " is " << str[i] << "\n";
}
int main() {
// NOTE: Do not edit this
char location[100] = "CodeChumIsLoveAndProgrammingAsWellYey";
while (true) {
printIndex(location);
}
return 0;
}
Comments
Leave a comment