Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-27
3
Medium Priority
?
263 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

604 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