-6

I can't figure out why my code is not compiling. I think I might have the wrong operators in my code though.

I've tried using different operator signs within functions.

if (encrypt <= 'A' && encrypt >= 'Z')
{
    encrypt = encrypt + shift;
else if(encrypt <= 'a' && >= 'z')
{
    encrypt = encrypt + shift;
if (decrypt <= 'A' && decrypt >= 'Z')
{
    decrypt = decrypt - shift;

else if(decrypt <= 'a' && >= 'z')

actual results are expected expression before >= token. the code above is snippets of what I think is wrong with my code. I'm trying to shift cipher.

Blaze
  • 16,736
  • 2
  • 25
  • 44
Chris
  • 3
  • 1
  • 3
    You are missing closing `}` braces. You get the compiler mixed-up. – Paul Ogilvie Jan 21 '19 at 08:35
  • 5
    `&& >= 'z'` is invalid syntax. do yu mean `&& encrypt >= 'z'`? – Paul Ogilvie Jan 21 '19 at 08:36
  • 2
    Your compiler will be warning you about these problems. Always enable additional compiler warnings (gcc/clang `-Wall -Wextra -pedantic`, for VS `/W3`). The warnings tell you the exact line where the problem exists (and many times the exact character within the line). Do not accept code until it compiles without warning. Let your compiler help you write better code. – David C. Rankin Jan 21 '19 at 08:43

2 Answers2

2

First of all, there are some braces missing in the if blocks. They look like this

if (encrypt <= 'A' && encrypt >= 'Z')
{
    encrypt = encrypt + shift;

But there should be a } after that. Also, you have conditions like those:

(encrypt <= 'a' && >= 'z')

I think you meant (encrypt <= 'a' && encrypt >= 'z') instead. Likewise for the encrypt part. All in all the code fragment should probably look like this:

if (encrypt <= 'A' && encrypt >= 'Z')
{
    encrypt = encrypt + shift;
}
else if (encrypt <= 'a' &&encrypt >= 'z')
{
    encrypt = encrypt + shift;
}
if (decrypt <= 'A' && decrypt >= 'Z')
{
    decrypt = decrypt - shift;
}

else if (decrypt <= 'a' && decrypt >= 'z')
{...}

A tip for future questions: your snippet was sufficient for demonstrating the issue, but it took some effort to get it to work. It is generally appreciated when there's a Minimal, Complete, and Verifiable example that people can just plop into their IDE and run.

Blaze
  • 16,736
  • 2
  • 25
  • 44
0
else if(encrypt <= 'a' && >= 'z')

what do you compare with z ?

must be

else if(encrypt <= 'a' && encrypt >= 'z')

same problem with

else if(decrypt <= 'a' && >= 'z')

must be

else if(decrypt <= 'a' && decrypt >= 'z')

Anyway it is impossible to value a value both <= a/A and >= z/Z, you have a serious problem of logic in your code


note you also have missing }

bruno
  • 32,421
  • 7
  • 25
  • 37