im having some issues with a program im trying to make to do my physics equations easier (what the teacher doesn't know... :P) im trying to make the code have the option to solve an equation, but have the option of solving for either of two of its variables. i attempted to use an if/else set up to make it work, but the compiler gives me issues with the else part of it...can anyone help? see code >>
#include <iostream>
using namespace std;
bool IsEqual(int x, int y)
{
return (x == y);
}
int main()
{
cout << "Enter a value: ";
int x;
cin >> x;
cout << "Enter another value: ";
int y;
cin >> y;
bool bEqual = IsEqual(x, y); //used to choose between the "distortion" and "fish" variables
if (bEqual)
cout << "input 'fish' value: ";
float fish; // value of heat expansion
cin >> fish;
cout << "input length of object: ";
int length; // length of object
cin >> length;
cout << "input initial temp: ";
int iTemp; //initial temp
cin >> iTemp;
cout << "input final temp: ";
int fTemp; //final temp
cin >> fTemp;
cout << "amount of distortion: " << (fTemp - iTemp) * length * fish;
if() will only do the next instruction unless you encase code in a block using braces. else needs to immediately follow the block. You need to do something like this:
1 2 3 4 5 6 7 8
if(bEqual)
{
// put if equal stuff here
}
else
{
// put not equal stuff here
}
OMG wow, thank you...i just now realized that i tried that before, but somehow never had the brackets on both the it and the else at the same time...i feel kinda stupid >.<