1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

What is wrong with my script

Discussion in 'C++' started by tboyrock2, Nov 14, 2014.

  1. tboyrock2

    tboyrock2 New Member

    Joined:
    Nov 14, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Code:
    #include <iostream>
    using namespace std ;
    
    int main()
    {
    // Program code goes here.
    
    char letter;  letter = ‘A’;   //Declared then initialized
    int number;   number = 100;
    float decimal = 7.5;
    double pi = 3.14159;
    bool isTrue = false;
    cout << “char letter:” << letter << endl ;
    cout << “int number:” << number << endl ;
    cout << “float decimal:” << decimal << endl ;
    cout << “double pi:” << pi << endl ;
    cout << “bool isTrue:” << isTrue << endl ;
    
    return 0 ;
    }
    




    please help!!
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Nothing is wrong in the above script unless we know what you want to be doing with that script.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    The only thing I can see wrong with this is the use of wrong quote marks: you're using ‘A’ instead of 'A', and “char letter:” instead of "char letter:" This would probably result in compiler errors.
     
  4. tboyrock2

    tboyrock2 New Member

    Joined:
    Nov 14, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    vars.cpp:8:24: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    char letter; letter = ‘A’; //Declared then initialized
    ^
    vars.cpp:8:28: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    char letter; letter = ‘A’; //Declared then initialized
    ^
    vars.cpp:8:27: error: use of undeclared identifier 'A'
    char letter; letter = ‘A’; //Declared then initialized
    ^
    vars.cpp:13:9: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “char letter:” << letter << endl ;
    ^
    vars.cpp:13:17: error: expected '(' for function-style cast or type construction
    cout << “char letter:” << letter << endl ;
    ~~~~ ^
    vars.cpp:13:24: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “char letter:” << letter << endl ;
    ^
    vars.cpp:14:9: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “int number:” << number << endl ;
    ^
    vars.cpp:14:16: error: expected '(' for function-style cast or type construction
    cout << “int number:” << number << endl ;
    ~~~ ^
    vars.cpp:14:23: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “int number:” << number << endl ;
    ^
    vars.cpp:15:9: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “float decimal:” << decimal << endl ;
    ^
    vars.cpp:15:18: error: expected '(' for function-style cast or type construction
    cout << “float decimal:” << decimal << endl ;
    ~~~~~ ^
    vars.cpp:15:26: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “float decimal:” << decimal << endl ;
    ^
    vars.cpp:16:9: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “double pi:” << pi << endl ;
    ^
    vars.cpp:16:19: error: expected '(' for function-style cast or type construction
    cout << “double pi:” << pi << endl ;
    ~~~~~~ ^
    vars.cpp:16:22: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “double pi:” << pi << endl ;
    ^
    vars.cpp:17:9: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “bool isTrue:” << isTrue << endl ;
    ^
    vars.cpp:17:17: error: expected '(' for function-style cast or type construction
    cout << “bool isTrue:” << isTrue << endl ;
    ~~~~ ^
    vars.cpp:17:24: error: non-ASCII characters are not allowed outside of literals
    and identifiers
    cout << “bool isTrue:” << isTrue << endl ;
    ^
    18 errors generated.



    those are the errors. i just want to execute it and see what it says. and xpi0t0s i dont understand what you mean,
     
  5. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Don't know how I can explain it in simpler terms. The compiler errors are exactly what I expected. You are using the wrong characters: for a char constant you surround the letter with single quote characters: one before, and one after. It's the same character twice. As in 'A'. What you're doing wrong is using quote characters that LOOK LIKE those but aren't.

    You are doing the same thing with string constants: instead of using "these" quotes, you are using quotes that look like 66 and 99, which is correct from a written English point of view, but this is C programming, not essay writing. Again it's the same character before and after the string and is on my keyboard on shift-2, if that's any help.

    If you still don't get it, then try getting someone near to you to read this update and see if they can understand it.
     

Share This Page