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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:48:53+00:00 2026-06-14T12:48:53+00:00

In the following code, I wish to give an option to the user to

  • 0

In the following code, I wish to give an option to the user to type ‘e’ to exit the code and see the results, instead of 100 as used in the code presently . But code is unable to run properly with ‘e’ from the terminal since scanf expects an integer, matching with the declared type. If I type in any character instead of an integer, scanf would store it in the variable in some manner. is that manner fixed? if it is fixed can I use that stored value to check if to exit program or not?

#include<stdio.h>
int main(void)
{
    int rating[11], x;

    for (int a = 0; a <= 11; a++)
        rating[a] = 0;

    while (1){
        printf("key in 100 to see the results\n");
        printf("Enter the rating on a scale from 1 to 10 ?");
        scanf("%i", &x);

        if ((x < 1 || x > 10) && x != 100)
            printf("bad entry ! \n");

        if (x == 100){
            printf("\nRatings..............No of responses\n");
            for (int y = 1; y <= 10; y++)
                printf("%2i.......................%2i\n", y, rating[y]);
            return 0;
        }

        rating[x]++;
    }
}
  • 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-14T12:48:55+00:00Added an answer on June 14, 2026 at 12:48 pm

    scanf returns the number of items successfully read (or -1 on error). So, you could conceivably check to see if scanf returns 0, and bail in that case; it would exit the program if anything non-numeric was entered.

    If you specifically want to check for 'e', the best bet is to fgets a whole line of input, check for your special cases using strcmp, then use atoi to get an integer.

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

Sidebar

Related Questions

Following code produces nothing but an error. I wish to retrieve REL attribute values
Following code does NOT work, but it expresses well what I wish to do.
I have used the following code to make a table but in the tag
I am a java devloper and I wish to convert following code to java
The following code always returns false (which is incorrect, as the user has Full
When I execute the following code #!/bin/sh # \ exec wish $0 ${1+$@} set
I have the following code: <!DOCTYPE HTML> <html> <head> <title>What</title> <style type=text/css> #box1 {
I have the following code: myFunction('test') I wish to set this on the onclick
I've used the following CSS code to load my font. This is in an
Suppose I have the following code that I wish to refactor: int toFuture() {

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.