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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:04:49+00:00 2026-06-18T06:04:49+00:00

I need to ask an input from a user and he/she should have the

  • 0

I need to ask an input from a user and he/she should have the ability to write a float number, and I need to do some calculation on the 2 numbers, but I’m having a problem after the isdigit test…even if I enter an integer its going to the continue;

This is my code:

#include <stdio.h>
#include <ctype.h>
char get_choice(void);
float calc(float number1, float number2);

int main()
{

    float userNum1;
    float userNum2;
    get_choice();

    printf("Please enter a number:\n");
    while ((scanf("%f", &userNum1)) == 1)
    {
        if (!isdigit(userNum1))
        {
            printf("Please enter a number:\n");
            continue;
        }


        printf("Please enter another number:\n");
        while ((scanf("%f", &userNum2) == 1))
        {
            if (!isdigit(userNum2))
            {
                printf("Please enter a number:/n");
                continue;
            }
            else if (userNum2 == '0')
            {
                printf("Please enter a numer higher than 0:\n");
                continue;
            }

        }

    }
    calc(userNum1, userNum2);
    return 0;
}

float calc(float number1, float number2)

{
    int answer;

    switch (get_choice())
        {
            case 'a':
                answer = number1 + number2;
                break;
            case 's':
                answer = number1 - number2;
                break;
            case 'm':
                answer = number1 * number2;
                break;
            case 'd':
                answer = number1 / number2;
                break;
        }
    return answer;
}

char get_choice(void)

{
    int choice;

    printf("Enter the operation of your choice:\n");
    printf("a. add        s. subtract\n");
    printf("m. multiply   d. divide\n");
    printf("q. quit\n");

    while ((choice = getchar()) == 1 && choice != 'q')
    {

        if (choice != 'a' || choice != 's' || choice != 'm' || choice != 'd')
        {
            printf("Enter the operation of your choice:\n");
            printf("a. add        s. subtract\n");
            printf("m. multiply   d. divide\n");
            printf("q. quit\n");
            continue;
        }


    }
    return choice;
}

Apologize for uploading the functions as well, but since I’m a newbie the problem might be there.
Cheers.

  • 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-18T06:04:51+00:00Added an answer on June 18, 2026 at 6:04 am

    isDigit() only takes a character input.
    The best way to check that you are getting input correctly is to use

    if(scanf("%f", &userNum) != 1) {
        // Handle item not float here
    }
    

    Since scanf() will return the number of items correctly scanned.

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

Sidebar

Related Questions

I need to ask a number from the user and have then if it
I need to get 10 numbers from the user, and than calc the amount
Hey all. I have a project that will require user input of anywhere from
I have to build an android project which takes input(command) from the user in
I need to ask the user to enter a positive non-zero integer from the
I need to write a program, that will ask a user to enter a
I have a SQL question that i need to ask the experts. To be
As part of my WiX-based installation, I need to ask the user to enter
I am creating some application, facebook application and i need to ask you something.
I have two lists: ask[] timeStamp[] I need to add the information in these

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.