The result is not displayed in the program that returns the sum of integers and real values, respectively.

Asked 2 years ago, Updated 2 years ago, 35 views

I created a program that shows the sum of integers and real numbers as follows, but the current program only commented Enter the values of integers a,b real numbers c,d but did not show any comments that represent the result of the sum of integers and real numbers.

I think I probably made a mistake with the main function, but I didn't understand the wrong part, so please reply if you understand.

Expected Results (Example Execution)

$./a.out
Enter an integer a: 5
Enter integer b: 7
Please enter a real number c: 4.8
Please enter a real number d: 5.8
The sum of the integer values is 12.
The total real value is 10.600000.

Created Programs

/* Function that returns the sum of two integer values a, b */
int sum_int(inta, intb)
{
    return a+b;
}

double sum_double(double a, double b)
{
    return a+b;
}

int main (void)
{
    inta,b,ans_int;
    double c,d,ans_double;

  printf("Enter a value for integer a:");
    scanf("%d", & a);
  printf("Enter a value for integer b:");
    scanf("%d", & b);
 an_int = sum_int(a,b);

 printf("Please enter a value of real number c:");
    scanf("%lf", &c);
  printf("Please enter a value of real number d:");
    scanf("%lf", &d);
   an_double=sum_double(c,d);

    return 0;
}

c

2022-09-30 19:47

2 Answers

It's only natural that there's no code to show the results (even though there's a code to add). Pass ans_int and ans_double to printf().If you want to display it as shown in the example, you need to specify the number of digits as well as format characters.For the time being, I will not write down the details in this answer.


2022-09-30 19:47

Such programs require you to write "View this string (output)" or "Enter this string (input)" as a program.In this case, the output is the printf function, and the input is the scanf function.

This program replaces the calculation results with variables as follows:

ans_int=sum_int(a,b);

However, it does not output any results, so there is no output. Use the printf function to output the value of the variable ans_int.


2022-09-30 19:47

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.