Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I don\'t know where I am going wrong but I have a feeling that it\'s with the fi

ID: 3787446 • Letter: I

Question

I don't know where I am going wrong but I have a feeling that it's with the first 2 'printf' of the code.

The problem comes with terminal not letting me enter a conditional variable.

This is the full code if it does not show well in the picture:

#include<stdio.h>
#include<math.h>

int main(void) {

   double a;
   double b;
   double c;
   int angle;
   char solveFor;
  
   // Prompt user to ente value of angle
   printf("Value for angle of triangle: ");
   scanf("%d", &angle);
  
   printf("Input variable solving for: ");
   scanf("%c", &solveFor);
  
   // Conditions for each solving for variable
   if(solveFor == 'C' || solveFor == 'c') {
           printf("Input a value for a: ");
           scanf("%lf", &a);
          
           printf("Input a value for b: ");
           scanf("%lf", &b);
          
           c = sqrt(( a * a ) + ( b * b ));
           printf("Value of c is: %f ", c);
          
   }   else if(solveFor == 'A' || solveFor == 'a') {
           printf("Input a value for b: ");
           scanf("%lf", &b);
          
           printf("Input a value for c: ");
           scanf("%lf", &c);
          
           a = sqrt(( b * b ) + ( c * c ));
           printf("Value of a is: %f ", a);
          
   }   else if(solveFor == 'B' || solveFor == 'b') {
           printf("Input a value for a: ");
           scanf("%lf", &a);
          
           printf("Input a value for c: ");
           scanf("%lf", &c);
          
           b = sqrt(( a * a ) + ( c * c ));
           printf("Value of b is: %f ", b);
      
   }   else {
           printf("Invalid variable. Please re-run program. ");
   }
   return 0;
}  

The formula be c2 is the special case of the Pythagorean theorem and works for triangles with a 90 oangle there is a more general theorem though and that is known as the law of cosines. Write a program that prompts for an angle and then solves for the missing variable if it is the special case of the theorem and outputs law of cosines case if it is the more general case. NOTE: problem amended to where the general case no longer must be solved for credit. Value for angle of triangle 131 Generic Law of Cosines case Value for angle of triangle: 90 Input variable solving for C Special case of Pythagorean Theorem Case Input a value for a: 1 Input a value for b: 1 Value of c is: 1.414214

Explanation / Answer

The problme in your code is " You have not handled the new line character". So after taking value of angle variable it takes new line character as value of "solveFor"

You can call "getchar()" method in the code to consume that new line character. So your modified code will be like this:

#include<stdio.h>
#include<math.h>

int main(void) {

    double a;
    double b;
    double c;
    int angle;
    char solveFor;
  
    // Prompt user to ente value of angle
    printf("Value for angle of triangle: ");
    scanf("%d", &angle);
    getchar();
    printf("Input variable solving for: ");
    scanf("%c", &solveFor);
  
    // Conditions for each solving for variable
     if(solveFor == 'C' || solveFor == 'c') {
            printf("Input a value for a: ");
            scanf("%lf", &a);
          
            printf("Input a value for b: ");
            scanf("%lf", &b);
          
            c = sqrt(( a * a ) + ( b * b ));
            printf("Value of c is: %f ", c);
          
    }    else if(solveFor == 'A' || solveFor == 'a') {
            printf("Input a value for b: ");
            scanf("%lf", &b);
          
            printf("Input a value for c: ");
            scanf("%lf", &c);
          
            a = sqrt(( b * b ) + ( c * c ));
            printf("Value of a is: %f ", a);
          
    }    else if(solveFor == 'B' || solveFor == 'b') {
            printf("Input a value for a: ");
            scanf("%lf", &a);
          
            printf("Input a value for c: ");
            scanf("%lf", &c);
          
            b = sqrt(( a * a ) + ( c * c ));
            printf("Value of b is: %f ", b);
      
    }    else {
            printf("Invalid variable. Please re-run program. ");
    }
    return 0;
}   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote