Look at that code
How may I aproach that. I would like to print the middle charactert of the string, if the string has an even number character ,I would like to print the right most character on the left half of the string
thanks

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    char data[20];
    double temp,variable,temporary;
    cout<<"input string:";
    cin.getline(data,20);
    cout<<"\nThe data you entered is: "<<data;
    cout<<"\nThe middle character of the input is: ";
    temporary=strlen(data);
    variable=temporary/2;
      if ((variable%2)==0)
     cout<<((data[temporary/2-1]));
    else
    cout<<((data[temporary/2]));
     
     getch();
    return 0;
}

Never mind guys ,I got it.
Thanks

if you wanted to save yourself a couple of lines of code, you could do this

int temporary = strlen(data) - 1;
cout << data[temporary/2] ;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.