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 7174345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:01:13+00:00 2026-05-28T16:01:13+00:00

I am currently taking a Programming Fundamentals college class that deals with the C

  • 0

I am currently taking a Programming Fundamentals college class that deals with the C programming language. One assignment that I have is to make a program that creates a random number from 1 to 10, and has the user guess the number. The problem I am having is that I have to use the isdigit() function to check that the guess is a number. I have used

scanf("%c", &userChar);

to store the argument to check that the guess is a digit in the following manner:

if isdigit(userChar)

However, I want to check to make sure that the number is between 1 and 10 by converting ‘userChar’ to an int variable to check in the following manner:

if (userNum >= 1 && userNum <= 10)

I have not yet learned how to do this so I was hoping someone from this site could help me. Also, I need it to check whether or not the user guessed the right number. Thanks in advance.

  • 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-05-28T16:01:14+00:00Added an answer on May 28, 2026 at 4:01 pm

    Since 10 cannot be stored in a single character, you would either need to use two digits, or to ask the user to guess a number from 0 to 9, inclusive.

    To make an int from a single-digit character use this code snippet:

    int digitVal = charDigit - '0';
    

    This works, because digits 0 through 9 are located next to each other in the ASCII encoding: the code for 1 equals the code for 0 plus one; the code for 2 equals the code for 0 plus two, and so on. Therefore, when you subtract the code of 0 (which is denoted as '0' in C) from a single-digit character, you get the integer value of the corresponding digit.

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

Sidebar

Related Questions

In the data structures class that I am currently taking, we have been tasked
I'm currently taking a math class in College called Scientific Computing and the professor
I am currently taking a class which is incorporating a topic I have not
I'm currently taking a class on programming the iPhone, and I am struggling with
I am currently taking a parallel programming class and our first programming exercise was
With reference to this programming game I am currently building. I have a Class
I'm currently taking a web development class and looking to go beyond the scope
I'm very new to Unix, and currently taking a class learning the basics of
I am currently designing and implementing a small programming language as an extra-credit project
I'm currently taking a computer security class and would like to try to port

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.