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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:13:22+00:00 2026-06-01T03:13:22+00:00

CODE: #include <stdio.h> main() { int nums[100], i; char answer; int count = 0;

  • 0

CODE:

#include <stdio.h>
main() {

    int nums[100], i;
    char answer;
    int count = 0;
    double avg;

    for (i = 0; i < 100; i++) {
        printf("Enter number %d: ", i + 1);
        scanf("%d", &nums[i]);
        printf("Another? ");
        scanf("%c", &answer);
        count += nums[i];
    }
}

RUN:

~> a.out
Enter number 1: 1
Another? Enter number 2: 2
Another? Enter number 3: 3
Another? Enter number 4: 4
Another? Enter number 5: 5
Another? Enter number 6: 6
Another? Enter number 7: 7
Another? Enter number 8: 8
Another? Enter number 9:

It’s supposed to ask me if I want to enter another number, but for some reason the scanf is not working. Also, I need to make it so that the user can enter 100 numbers, or any number under that, being prompted with a question of “do you want to enter another number”. If the answer is no, it terminates, if it is yes, it carries on.

  • 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-01T03:13:24+00:00Added an answer on June 1, 2026 at 3:13 am

    Your first scanf leaves a newline in the buffer. It’s because %d ignores trailing blanks while %c doesn’t. Use this cheap trick to make the second scanf eat the blanks:

    scanf(" %c", &answer);
           ^
    

    The issue is common enough, you can read more about it in the C FAQ.

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

Sidebar

Related Questions

Code : #include stdio.h #include string.h int main() { char *p = abc; printf(p
Why does this code: #include <stdio.h> int main(int argc, char** argv) { printf(%lld\n, 4294967296LL);
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
#include<stdio.h> int main() { char a[5]=hello; puts(a); //prints hello } Why does the code
I have a program that has this code : #include<stdio.h> main(){ int input; char
Consider this C code: #include stdio.h int main(void) { int count = 5; unsigned
When I run the following code: #include <stdio.h> int main(int argc, char *argv[]) {
Here is my code: #include <stdio.h> #include <stdlib.h> int main(){ int n=10; char *s=
When i execute this code #include<stdio.h> int main() { int (*x)[5]; printf(\nx = %u\nx+1

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.