Solved

How do i take each individaul number and put them in the variable

Posted on 2004-09-27
3
207 Views
Last Modified: 2012-05-05
#include <iostream>

using namespace std;

int main(){

String =0;
NumOne = 0;
NumTwo = 0;
NumThree = 0;
NumFour = 0;
NumFive = 0;

     cout << "Please Enter A Palindrome:  ";
     cin >> String;

     if(NumOne == NumFive && NumTwo == NumFour)
     cout << " Thats correct its a Palindrome " << endl;
     
     else  
     cout << " INCORRECT INVALID PALINDROME" << endl;

     return 0;
}

How do i get what they input into my variables the first character in nume one the second in numtwo and so on .........
Thanks
0
Comment
Question by:tedschnieders
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
You could use

#include <iostream>
#include <string>

using namespace std;

void reverse_string ( string& in, string& out) {

    int nSize = in.size();
    out.erase();
    out.resize(nSize);

    for ( int i = 0; i < nSize; ++i) out[i] = in[nSize - i - 1];
}

int main(){

string strOrig;
string strReverse;

     cout << "Please Enter A Palindrome:  ";
     cin >> strOrig;

    reverse_string(strOrig,strReverse);

    if(strOrig == strReverse)
    cout << " Thats correct its a Palindrome " << endl;
     else  
    cout << " INCORRECT INVALID PALINDROME" << endl;

    return 0;
}
0
 

Author Comment

by:tedschnieders
Comment Utility
Is there anyway i can break down the string into individual numbers or letters entered
 
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
Comment Utility
The operator[] that is used to reverse the string does exactly that. But, breaking that down into individually declared variables will limit you in terms of the size of the strings entered. You could of course use

}int main(){

string str;
char c0, c1, c2, c3 c4;

    cout << "Please Enter A Palindrome:  ";
    cin >> str;

    c0 = str[0];
    c1 = str[1];
    c2 = str[2];
    c3 = str[3];

    //...
 
   return 0;
}


0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now