C/C++ :: Palindrome Function Only Return False?
Apr 29, 2015
I have a text file that consists of:
1457887541
Madam
Able was I ere I saw Elba
Straw? No, too stupid a fad. I put soot on warts.
Class is cancelled today
And all of them are returning false as a palindrome and am not sure why that is so.
bool isPalindrome(const char *input){
int first = 0;
int last = strlen(input) - 1;
//begin loop to compare first position with last
while(last > first){
[Code] .....
View 3 Replies
Apr 26, 2014
Write a function palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).
Code :
#include <vector>
#include <iostream>
using namespace std;
void palindrome(vector<int>);
[Code] .....
View 4 Replies
View Related
Nov 9, 2014
I was instructed to write a binary search function which would return true if an element, inputted by the user, was found in the array, and false if it was not. I'm not sure why, but my function always returns false. My code is as follows.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
//binary search function
bool search (int array[], int item)
[Code] ....
Why my code does not fulfill it's purpose???
View 7 Replies
View Related
Sep 11, 2014
is it true or false
a function like void myfun(int num){} can receive type "int var" but can't receive type "const int var"
AND
a function like void myfun(const int num){} can receive both type "int var" and also type "const int var"
View 3 Replies
View Related
Mar 24, 2014
I have a bool type function and set it to explicitly return false, but I am still getting true as the return.
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]){
double coeffs[3];
double roots[2];
[code].....
View 7 Replies
View Related
Apr 2, 2013
I'm havin trouble outputing different false statements in a boolean function... I'm currently working on a "secret number game" program which must generate a secret number and inform the user if his/her guess number is to high, to low or correct. I know boolean return true and false.. If the number is correct, the true statement will appear, if false... THAT'S where my problem starts cause now I have TWO statements to output..In a Function.. How do I make my program able to tell if the number guessed is "too high" or "too low" ?
View 6 Replies
View Related
Jun 24, 2013
I'm trying to write a function which can recognize whether a word is a palindrome. if it's the case , it must return 1 on screen, otherwise 0. This is the code which return 0 even in case of a palindrome...
Code:
int IsPalindrom(char String[]){
int i,l;
int counter=0;
for(i=0;;i++){ //counts the number of array elements
[Code] ....
View 9 Replies
View Related
Feb 28, 2014
I had an assignment to do a palindrome program but im stuck in this part.
"This c-string will be sent to a function that will remove all spaces and punctuation marks from its c-string as well as change any uppercase letters to lowercase. Use string tokens to eliminate the spaces & punctuation marks. Make sure you include the NULL as you concatenate the tokens into a c-string. Then copy back into the original c-string for the pass by reference."
void tokenptr(char drome[]) {
char *token;
size_t i;
token = strtok(drome, " ,.!:;?");
while (token != '