?
Solved

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

Posted on 2004-09-27
3
Medium Priority
?
255 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 12165034
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
ID: 12165122
Is there anyway i can break down the string into individual numbers or letters entered
 
0
 
LVL 86

Accepted Solution

by:
jkr earned 2000 total points
ID: 12165148
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

764 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