Challenge extended


#1

I decided to extend the challenge by adding if then else to add an output but it is not working.

What am I doing wrong?[code]//
// main.c
// Triangle
//
// Created by Wendy Meyeroff on 5/2/14.
// Copyright © 2014 Big Nerd Ranch. All rights reserved.
//

#include <stdio.h>
static int totalValue = 180;

int main(int argc, const char * argv[])
{
float angleA = 20;
float angleB = 60;
float angleC = totalValue - (angleA + angleB);
printf(“The third angle of the triangle is %.0f.\n”, angleC);

if (angelA = 90);
{
    printf("The triangle is a Right Triangle");
}
else if (angleC = 90);
{
    printf("The triangle is a Right Triangle");
}
else if (angleB = 90);
    
 printf("The triangle is a Right Triangle");

return 0;

}
[/code]
What i want to do is print “the triangle is a right triangle” if one of the angles is 90.


#2

Good try but you have some interesting coding errors:

  • Misuse of the assignment operator;
  • semicolons in the wrong places; and
  • missing braces.

[quote] if (angelA = 90); <-- this semicolon should not be here, and '=' should be '==' { printf("The triangle is a Right Triangle"); } else if (angleC = 90); <-- this semicolon should not be here, and '=' should be '==' { printf("The triangle is a Right Triangle"); } else if (angleB = 90); <-- this semicolon should not be here, and '=' should be '==' <-- missing brace ({) printf("The triangle is a Right Triangle"); <-- missing brace (}) [/quote]
This is what you wanted to write:

if (angelA == 90)
{
    printf ("The triangle is a Right Triangle\n");
}
else if (angleC == 90)
{
     printf ("The triangle is a Right Triangle\n");
}
else if (angleB == 90)
{
     printf ("The triangle is a Right Triangle\n");
}

which can also be written as:

if (angelA == 90 || angleB == 90 || angleC == 90)
{
    printf ("The triangle is a Right Triangle\n");
}

The misuse of the assignment operator is a common coding error, even among experienced programmers:

if (foo = bar) {
    ...
}

The above statement is not testing for equality; it is, most likely by a coding accident, testing for nonzero. If the value of foo becomes nonzero after the assignment, then the if statement’s block is executed.


#3

Thank You

I had tried to put all three together but it didn’t work so I tried them seperatly.

I am new to language programing, but I did program using a Data base called Helix.