Question

C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings...

C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings to double values. Calculate the sum,difference,and product of these values and print them.

int main(){
   // character string value array for user
   char stringValue[10];
  
   double sum=0.0;// initialize sum to store the results from 2 double values
  
   double difference=0.0; // initialize difference to store the results from 2 double values
  
   double product = 0.0; // intitialzie product to store the results from 2 double values
  
   int x; // initialize x for loop counter
  
   // loop 2 times from 1 to 2
   for(x=1;x<=2;x++){
      
       // prompt user to enter floating point string value
       printf("Enter the floating point string value:\t");
      
       // gets function to get string values
       scanf("%s",stringValue);
      
       // atof converts the string into double values
       sum+=atof(stringValue);
      
       difference -= atof(stringValue);
      
       product *= atof(stringValue);
      
      
   }// end for loop
  
   // Display sum,diffence, and product of 2 values entered from user
   printf("\nThe total of the two values entered is %f\n",sum);
  
   printf("The difference of the two values entered is %f\n",difference);
  
   printf("The product of the two values entered is %f\n",product);
  
   return 0;
  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>
#include <stdlib.h>

int main() {
    // character string value array for user
    char stringValue[10];

    double sum = 0.0;// initialize sum to store the results from 2 double values
    double difference = 0.0; // initialize difference to store the results from 2 double values
    double product = 1.0; // intitialzie product to store the results from 2 double values
    int x; // initialize x for loop counter

    // loop 2 times from 1 to 2
    for (x = 1; x <= 2; x++) {
        // prompt user to enter floating point string value
        printf("Enter the floating point string value:\t");
        // gets function to get string values
        scanf("%s", stringValue);
        // atof converts the string into double values
        sum += atof(stringValue);
        if (x == 1)
            difference = sum;
        else
            difference -= atof(stringValue);
        product *= atof(stringValue);
    }// end for loop

    // Display sum,diffence, and product of 2 values entered from user
    printf("\nThe total of the two values entered is %f\n", sum);
    printf("The difference of the two values entered is %f\n", difference);
    printf("The product of the two values entered is %f\n", product);
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
C Programming: Write a program that inputs two strings that represent floating-point values, convert the strings...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT