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

  • Home
  • SEARCH
  • 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 9145625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:33:39+00:00 2026-06-17T10:33:39+00:00

#include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include mainl.h static struct prod_details pd;

  • 0
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "mainl.h"

static struct prod_details pd;

char *getinput(char *inp)
{
    printf("Enter the amount of the product %d:\n",pd.no_prod+1);
    gets(inp);
    return inp;
}

void print()
{
    printf("........................\n");
    printf("No of Product is: %d\n",pd.no_prod);
    printf("Grant Total is : %.2f\n",pd.total);
    printf("........................\n");
}

int check(char *str) 
{
    int i;
    if(strlen(str) == 0)
        return 2;
    for(i=0;i<strlen(str);i++)
    {
        if(str[i] == '-')
            return 3;
        if(isalpha(str[i]) != 0)
            return 0;
    }
    return 1;
}

void calc(char *str)
{
    pd.array[pd.no_prod]=atof(str);
    pd.total=pd.total+pd.array[pd.no_prod];
    printf("Total is:%.2f\n",pd.total);
    pd.no_prod++;
}

int main()
{
    int chkflg,i=0,flag=0,cflag=0;
    char ch;
    char input[1024];
    printf("..................\n");
    printf("..CASE  RIGISTER..\n");
    printf("..................\n");
    //strcpy(input,getinput(i+1));
    //printf("%s\n",input);
    do
    {
        strcpy(input,getinput(input));
        chkflg=check(input);
        switch(chkflg)
        {
            case 0:
                printf("Please Enter Correctly...!!!\n");
                printf("You Have entered Wrongly.!!!\n");
                flag=0;
                break;
            case 1:
                calc(input);
                flag=1;
                break;
            case 2:
                printf("You didnt enter anything.!!!\n");
                flag=0;
                break;  
            case 3:
                printf("Coundnot Subtract the Amount..!!!\n");
                flag = 0;
                break;      
        }
        if(flag == 0)
        {
            printf("Do u want to continue(y/n)");
            ch=getchar();
            if(ch == 'y')
            {
                flag=1;
                //continue;
            }
            else if(ch == 'n')
            {
                printf("Thank u..!!!\n");
                break;
            }
            else
            {
                printf("You didn't Enter Properly...!!!\n");
                break;
            }
        }   
    }while(flag == 1);
    print();
    return 0;
}

This is the program for calculating the bill.This Program works well for correct input(eg.double). But The problem is, if we enter wrongly as string, it shows the corresponding cases, and ask whether to continue or not. if we want to continue,it produces the output as:

You Have entered Wrongly.!!!
Do u want to continue(y/n)y
Enter the Amount of the product 3:
You didn't enter anything.!!!
Do u want to continue(y/n)

It does not get further the input.I was working with gdb. But I couldn’t understand why it couldn’t get the input further. Please help me to resolve this problem.Thank u 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-06-17T10:33:40+00:00Added an answer on June 17, 2026 at 10:33 am

    When you use getchar the newline you press after the y is left in the input stream. Then when you do gets it reads that newline and you have an empty line.

    One way to solve this is to use e.g. scanf with a space after the format, as this will tell scanf to eat all whitespace after the read character:

    printf("Do you want to continue(y/n)");
    scanf("%c ", &ch);
    

    Another solution is to use fgets to read the whole line, and extract the answer using e.g. sscanf.

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

Sidebar

Related Questions

#include<stdio.h> #include<stdlib.h> #include<ctype.h> #include<string.h> struct person *create_node(char *, char *,int); void addnode(char *,char *,int,struct
My code #include <stdio.h> #include <stdlib.h> #include <ctype.h> void getData(short int *number, char *string)
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
#include<stdlib.h> #include<string.h> #include<stdio.h> int pstrcmp( char **p,char **q) { return strcmp(*p,*q) ; } int
#include<stdio.h> #include<string.h> #include<stdlib.h> int main() { // int char str[40],ch; FILE*fp,*fp1,*fp2; fp=fopen(ide_input,w); fp1=fopen(error_log,w); fp2=fopen(lex_output,w);
#include<iostream> #include<stdlib.h> #include<string.h> #include<stdio.h> using namespace std; union type{ int a; char b; int
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include dictionary.h #define HASH_SIZE
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<stdbool.h> char output[17]={0}; const char* change_mac(char ch[100]) { int i =
Please see this piece of code: #include<stdio.h> #include<string.h> #include<stdlib.h> int main() { int i
This is my socket server with fork: #include <stdio.h> #include <string.h> #include <stdlib.h> #include

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.