0

I'm posting this bit of code for an assignment mainly to see whether there is, in fact, a non-ASCII character in my code. Should I consider a hex editor? Or is there something entirely different that's preventing me from compiling my code? I'm totally lost and haven't been able to notice anything. Here is the error output:

||=== Build: Debug in as13 (compiler: GNU GCC Compiler) ===|
C:\Users\NK\Documents\CS110\as13\main.cpp|10|error: stray '\223' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|10|error: stray '\224' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|15|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|15|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|18|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|18|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|21|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|21|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|24|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|24|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|27|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|27|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|30|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|30|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|33|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|33|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|36|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|36|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|39|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|39|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|42|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|42|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|45|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|45|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|48|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|48|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|51|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|51|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|54|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|54|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|57|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|57|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|60|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|60|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|63|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|63|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|66|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|66|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|69|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|69|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|72|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|72|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|75|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|75|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|78|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|78|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|81|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|81|error: stray '\222' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|84|error: stray '\221' in program|
C:\Users\NK\Documents\CS110\as13\main.cpp|84|error: stray '\222' in program|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s))
===|
#include <iostream>
#include <string>
using namespace std;
int main()
{

int digit;
char letter;

cout << “Enter a single letter: ” << endl; // <-- Line 10
cin >> letter;

switch (letter){

case ‘a’:
    digit = 2;
    break;
case ‘b’:
    digit = 2;
    break;
case ‘c’:
    digit = 2;
    break;
case ‘A’:
    digit = 2;
    break;
case ‘B’:
    digit = 2;
    break;
case ‘C’:
    digit = 2;
    break;
case ‘d’:
    digit = 3;
    break;
case ‘e’:
    digit = 3;
    break;
case ‘f’:
    digit = 3;
    break;
case ‘D’:
    digit = 3;
    break;
case ‘E’:
    digit = 3;
    break;
case ‘F’:
    digit = 3;
    break;
case ‘g’:
    digit = 4;
    break;
case ‘h’:
    digit = 4;
    break;
case ‘i’:
    digit = 4;
    break;;
case ‘G’:
    digit = 4;
    break;
case ‘H’:
    digit = 4;
    break;
case ‘I’:
    digit = 4;
    break;
case ‘j’:
    digit = 5;
    break;
case ‘k’:
    digit = 5;
    break;
case ‘l’:
    digit = 5;
    break;
case ‘J’:
    digit = 5;
    break;
case ‘K’:  //
    digit = 5;
    break;
case ‘L’:   // <-- Line 84
    digit = 5;
    break;
case ‘m’:
    digit = 6;
    break;
case ‘n’:
    digit = 6;
    break;
case ‘o’:
    digit = 6;
    break;
case ‘M’:
    digit = 6;
    break;
case ‘N’:
    digit = 6;
    break;
case ‘O’:
    digit = 6;
    break;
case ‘p’:
    digit = 7;
    break;
case ‘q’:
    digit = 7;
    break;
case ‘r’:
    digit = 7;
    break;
case ‘s’:
    digit = 7;
    break;
case ‘P’:
    digit = 7;
    break;
case ‘Q’:
    digit = 7;
    break;
case ‘R’:
    digit = 7;
    break;
case ‘S’:
    digit = 7;
    break;
case ‘t’:
    digit = 8;
    break;
 case ‘u’:
    digit = 8;
    break;
 case ‘v’:
    digit = 8;
    break;
 case ‘T’:
    digit = 8;
    break;
 case ‘U’:
    digit = 8;
    break;
 case ‘V’:
    digit = 8;
    break;
 case ‘w’:
    digit = 9;
    break;
 case ‘x’:
    digit = 9;
    break;
 case ‘y’:
    digit = 9;
    break;
 case ‘z’:
    digit = 9;
    break;
 case ‘W’:
    digit = 9;
    break;
 case ‘X’:
    digit = 9;
    break;
 case ‘Y’:
    digit = 9;
    break;
 case ‘Z’:
    digit = 9;
    break;

 }

 cout << "digit is " << digit << endl;
 return 0;

 }
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
nkeledjian
  • 11
  • 5
  • Yo used "smart" quotes (`“‘`) in your strings and character literals. Change them to normal quotes. (`"'`) – Dark Falcon Oct 05 '18 at 17:01
  • 1
    What quote characters are you using? What editor did you use to write this? – stark Oct 05 '18 at 17:01
  • In [Windows-1252](https://en.wikipedia.org/wiki/Windows-1252), 221 and 222 (octal) correspond to [LEFT SINGLE QUOTATION MARK](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128) and [RIGHT SINGLE QUOTATION MARK](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8192&number=128). – Peter Mortensen May 06 '23 at 01:10
  • This is a ***very*** common error when copying code from web pages, [PDF](https://en.wikipedia.org/wiki/Portable_Document_Format) documents, through chat (e.g. [Skype Chat](https://en.wikipedia.org/wiki/Features_of_Skype#Skype_chat) or [Facebook Messenger](https://en.wikipedia.org/wiki/Facebook_Messenger)), etc. The canonical question is *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen May 06 '23 at 01:11
  • 221 and 222 (octal) are 0x91 and 0x92, respectively. [Code page table](https://en.wikipedia.org/wiki/Windows-1252#Codepage_layout). – Peter Mortensen May 06 '23 at 01:17

2 Answers2

1

You're using the non-ASCII characters and instead of ASCII " as string quotation marks, and you're using the non-ASCII and instead of ' for character quotation marks. Don't do that.

jwodder
  • 54,758
  • 12
  • 108
  • 124
  • I am using CodeBlocks. Also, I couldn't tell you why I was using "smart" quotes but I changed them all to ASCII quotes " and it worked. Thank you jwodder! – nkeledjian Oct 06 '18 at 06:13
0

I agree with the other answers. Why not try using an online C++ Compiler? I don't know how you got the other type of quotes instead of the normal " ones. Maybe, type this out again on the online compiler, and it should work. Moreover, as Capital and Small Letters have different ASCII values, so logically your program is correct. Only the problem is with quotes as rightly pointed out by @jwodder.

JChat
  • 784
  • 2
  • 13
  • 33