Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:10:51+00:00 2026-06-18T12:10:51+00:00

Beginning programmer here… I’m writing a very simply program for my computer science class

  • 0

Beginning programmer here…

I’m writing a very simply program for my computer science class and I ran into an issue that I’d like to know more about. Here is my code:

#include <iostream>

using namespace std;

int main(int argc, const char * argv[])
{
    char courseLevel;

    cout << "Will you be taking graduate or undergraduate level courses (enter 'U'"
            " for undergraduate,'G' for graduate.";
    cin >> courseLevel;

    if (courseLevel == "U")
    {
        cout << "You selected undergraduate level courses.";
    }

    return 0;
}

I’m getting two error messages for my if statement:
1) Result of comparison against a string literal is unspecified (use strncmp instead).
2) Comparison between pointer and integer (‘int’ and ‘const char*’).

I seem to have resolved the issue by enclosing my U in single quotes, or the program at least works anyway. But, as I stated, I’d simply like to understand why I was getting the error so I can get a better understanding of what I’m doing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:10:52+00:00Added an answer on June 18, 2026 at 12:10 pm

    You need to use single quotes instead.

    In C, (and many other languages) a character constant is a single character1 contained in single quotes:

    'U'
    

    While a string literal is any number of characters contained in double quotes:

    "U"
    

    You declared courseLevel as a single character: char courseLevel; So you can only compare that to another single char.

    When you do if (courseLevel == "U"), the left side is a char, while the right side is a const char* — a pointer to the first char in that string literal. Your compiler is telling you this:

    Comparison between pointer and integer (‘int‘ and ‘const char*‘)


    So your options are:

    if (courseLevel == 'U')       // compare char to char
    

    Or, for sake of example:

    if (courseLevel == "U"[0])    // compare char to first char in string
    

    1. Note for completeness: You can have mulit-character constants:

      int a = ‘abcd’; // 0x61626364 in GCC

    But this is certainly not what you’re looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginning programmer studying computer science and I've been told many times that
I'm a beginning programmer and the I&CS program at our school starts us off
I'm a beginning programmer who is trying to capture data from this source Here's
I am a beginning programmer. I've been writing codes on a mastermind solver in
Beginning rails programmer here. I'm trying to convert a hash to both xml and
I'm a novice Java programmer, and am just now beginning to expand into the
I'm a beginning programmer in Ruby on Rails 3. I currently want to implement
On paper, binary arithmetic is simple, but as a beginning programmer, I'm finding it
I am a beginning javascript programmer. I am trying to create something similar to
I'm a beginning programmer. I'm trying use Universal image loader to display images parsed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.