conditional statments

I have made my own original code and when it compiles the conditional statements are ignored and both statements are printed

as

[code]

// triangle angle guessing
#include <iostream> /* Opening Delcaration */
#include <cmath> /* May be need for math operations */
#include <string.h> /* May be Needed for string var */
using namespace std;

int main()
{

// declaring variables
int i; /* declaring scope */
int a; /* Variable A */
int b; /* Variable B */
int c; /* Result */

a = 45; /* Value A */
b = 45; /* Value B */
c = 90;


// print the question
cout << "if a trangle has two angles that are 45 degrees what is the missing angle " << endl;

cout << "enter a number: " << endl;

// input the answer
cin >> i;

if (i = 90)
cout << "that is right" << endl;
else (i > 90 or i < 90 );
cout << " the answer is 90 " << endl;

return 0;
}

it prints both of the statements even if they ain't right
Do you realize that the operator= is the assignment operator, so i will always be equal to 90?

Also an else statement has no condition statement.

Last edited on
I want it so that when you enter any number other than 90 it will only write

"the answer is 90 "

and when it is right to write

" that is right"
an I have been changing the code to do this

and it said that I had to declare I in the scope when I jut wanted you to type the input number
Because you're if statement is using the assignment operator it should always print "that is right" no matter what you enter into the program. Your compiler should be able to warn you about these kind of problems, never ignore warnings.

In C++ there is a difference between the assignment operator= and the comparison operator==.



Topic archived. No new replies allowed.