Take a string from user then change the last letter to upper and write the 2nd letter and 4th letter from the string.
Generate 10 random integers from <-10,5>. Print these numbers. To the even numbers, add 100 and print them again.
I wrote this code; is it right?
#include <iostream>
#include <string>
#include<time.h>
#include <array>
using namespace std;
int main()
{
string a;
cin >> a;
cout << a << endl;
a.back() = toupper(a.back());
cout << a<<endl;
cout << "2 letter is "<<a.at(2) << endl;
cout <<" 4 letter is "<< a.at(4) << endl;
srand(unsigned(time(0)));
int tab[10];
for (int i = 0; i < 10; i++)
{
int z = (rand() % 16) - 10;
tab[i] = z;
}
for (int i = 0; i < 10; i++)
{
cout << tab[i] << endl;
}
cout << "===============" << endl;
for (int i = 0; i < 10; i++)
{
if (tab[i] % 2 == 0)
{
tab[i] += 100;
}
}
for (int i = 0; i < 10; i++)
{
cout << tab[i] << endl;
}
}