Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Segmentation fault (core dumped)

0 votes
asked Apr 15, 2020 by Mausam Acharya (120 points)
#include<stdio.h>
#include<math.h>
int main()
{
    double baseprice;
    int tip_per;
    int tax_per;
    scanf("%lf",baseprice);
    scanf("%d",tip_per);
    scanf("%d",tax_per);
    double tp=(double) tip_per;
    double tx= (double)tax_per;
    double tip=baseprice*(tp/100);
    double tax=baseprice*(tx/100);
    double total_bill=round(baseprice+tip+tax);
    printf("%lf",total_bill);
    return 0;
}

2 Answers

0 votes
answered Apr 16, 2020 by jr (150 points)

scanf needs pointer so use

 scanf("%lf",&baseprice);
 scanf("%d",&tip_per);
 scanf("%d",&tax_per);

0 votes
answered Apr 16, 2020 by Husoski (520 points)

The scanf() function needs pointers to the variables being read in, not current values.  Use the & operator to create a pointer to a variable:


    scanf("%lf", &baseprice);
    scanf("%d", &tip_per);
    scanf("%d", &tax_per);

Also, the printf format for a double is just %f, not %lf.

    printf("%f", total_bill):

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...