Hi new member here! i'm having a problem with my code here but I really don't know why, its in the line where i'll comment..

#include<iostream>
using namespace std;

void convert(char*);

void main(){
    char r, sen[200];

    do{
        cout<<"Enter text: ";
        cin.getline(sen, 200);

        convert(sen);

        cout<<"Try again?[Y/N] ";
        cin>>r;
        cin.ignore();
    }while(r=='y' || r=='Y');
}

void convert(char* sen){
    int i, max;
    char temp1, temp2, temp3;

    if(*sen!='a' || *sen!='A' || *sen!='e' || *sen!='E' || *sen!='i' || *sen!='I' ||
        *sen!='u' || *sen!='U' || *sen!='o' || *sen!='U'){ // IN HERE
        for(i=0; *(sen+i)!='\0'; i++);

        max=i;
        temp3 = *sen;
        i--;
        temp2 = *(sen+i);
        for(; i!=-1; i--){
            temp1 = *(sen+i-1);
            *(sen+i-1) = temp2;
            temp2 = temp1;
        }

        max--;
        *(sen+max) = temp3;
        max++;
        *(sen+max) = 'a';
        *(sen+max+1) = 'y';
        *(sen+max+2) = '\0';
    }
    else{
        for(i=0; *(sen+i)!='\0'; i++);
        *(sen+i) = 'h';
        *(sen+i+1) = 'a';
        *(sen+i+2) = 'y';
        *(sen+i+3) = '\0';
    }


    for(i=0; *(sen+i)!='\0'; i++)
        cout<<*(sen+i);
    cout<<endl;
}

In that area where I commented is the problem I think, you see even if the statement is false the code still passes through those statements but when I tried to only have one condition in that if statement it worked fine, its just with multiple conditions that it doesn't work normally, why is this?

Recommended Answers

All 3 Replies

If at least one of those conditions is true it will pass on to the next set of statements
try using the && operator

if(*sen!='a' || *sen!='A'

This is always true, yes? *sen can't equal both 'a' and 'A', so it must NOT EQUAL at least one of them. Since you have multiple tests with the || operator, if any of them are true, the statement is true. Hence that if statement will always be true. Perhaps you meant to use the && operator or something else?

ofcourse...stupid stupid me...really thanks a lot man..:D

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.