I'm trying to make so it would check if letter i and i+1 are alike. If so it'd drop "denied" else "accepted". i dont understand what I did wrong though:

#include <iostream>
using namespace std;

int main()
{
    char pass[5];
    bool correct=false;
    cout<< "pass: "; cin>> pass;

          for (int i=0; i<5; i++)
          {
              if (pass[i] != pass[i+1])
              correct=true;
          }

    if (correct==false) cout<< "denied";
    else cout<< "accepted";
          return 0;
    }

Recommended Answers

All 4 Replies

can you give a brief description of your question.. and the kind of out put you are expecting ..

I dont know what you are trying to do but in line 12 during the last iteration of the loop i=4, i+1 will be 5 that will go out of bounds for the array pass. Run the loop till i<4 because there will be no i+1 for the last element.

What this code is supposed to do is check the word given. For example i enter 'abcd'- nearby letters are different so it should give "accepted", but if i enter for example abbc then it'll give "denied" as nearby letters match

problem solved, case closed so to speak :)

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.