I have been having trouble with a really basic program and it's making me feel bad! I narrowed it down to 1 error but I can't figure out what is wrong...

-------------------------------------------------------------------------------------

bool end = false;

It says there is a syntax error here --> while(!end)

#include <iostream.h>

int main ()

{
int m;
int n;
int c;//variables for Pythagorean Theorem

cout << "Please enter a number.\n";
cin >> m;//enter the larger number
cout << "Now enter a number smaller than the first.\n";
cin >> n;//enter the smaller number
if(n >= m)//Check for correct input.
cout << "You entered incorrect input.\n";
if(n >= m)//I couldn't get it to perform 2 actions.
return 0;

c = (m * m) + (n * n); //find the solution
cout << "Your answer is " << c << '\n';
cout << "Would you like to perform another problem? (y, n) ";
if(n)
end = true;
return 0;
}

2. Welcome to the boards. First off

Code tags are nice

Code:
```#include <iostream.h>

int main ()
{
int m;
int n;
int c;//variables for Pythagorean Theorem

cout << "Please enter a number.\n";
cin >> m;//enter the larger number
cout << "Now enter a number smaller than the first.\n";
cin >> n;//enter the smaller number
if(n >= m)//Check for correct input.
cout << "You entered incorrect input.\n";
if(n >= m)//I couldn't get it to perform 2 actions.
return 0;

c = (m * m) + (n * n); //find the solution
cout << "Your answer is " << c << '\n';
cout << "Would you like to perform another problem? (y, n) ";
if(n)
end = true;
return 0;
}```
umm....there's no while loop in that code...

3. Ok, sorry...I jumped the gun a bit on that post and didn't read about code tags...

Code:
```bool end = false;

while(!end)

#include <iostream.h>

int main ()

{
int m;
int n;
int c;//variables for Pythagorean Theorem

cout << "Please enter a number.\n";
cin >> m;//enter the larger number
cout << "Now enter a number smaller than the first.\n";
cin >> n;//enter the smaller number
if(n >= m)//Check for correct input.
cout << "You entered incorrect input.\n";
if(n >= m)//I couldn't get it to perform 2 actions.
return 0;

c = (m * m) + (n * n); //find the solution
cout << "Your answer is " << c << '\n';
cout << "Would you like to perform another problem? (y, n) ";
if(n)
end = true;
return 0;
}```

4. Code:
`while(!end)`
you can't have while loops outside of functions. Place it inside of the main function and you'll be fine.

5. the loop must be inside of main()

6. while(!end)
why I cann't find this statement.

7. Code:
```#include <iostream>
using namespace std;

int main()
{

bool end = false;
int i = 0;
while(!end){
cout << i << endl;
i++;
if(i==3)
end = true;
}

return 0;
}```

8. I did that and now it says that "answer" is an undeclared identifier...

9. First, please use the [.code] and [./code] tags. It makes everyone's life much easier.

Secondly, I'm going to re-write your program. See if you can make heads or tails of it.

Code:
```#include <iostream>

int main ()
{
int m, n, c; //variables for Pythagorean Theorem

std::cout << "Please enter a number.\n";
std::cin >> m; //enter the larger number

std::cout << "Now enter a number smaller than the first.\n";
std::cin >> n; //enter the smaller number

if(n >= m) //Check for correct input.
{
std::cout << "You entered incorrect input.\n";
return(0);
}

c = (m * m) + (n * n); //find the solution

std::cout << "Your answer is " << c << '\n';
std::cout << "Would you like to perform another problem? (y, n) ";

if(answer == 'n') return(0);
else return(0);
}```
Third, I'm going to ask exactly what you're trying to achieve here.

10. you're using the while loop without any curly braces, meaning it only extends for one command.

To make the while loop work you need to use:

{

}

example:
Code:
```while(<test something here>)
{
// Code goes here
}```

11. lol, it's a project for school...and I wanted to make it loop for brownie points.

12. what's the std:: before cout and cin?

13. Hi ChaosTony,

If you're trying to calculate the hypotenuse of a right angle triangle I think you'll need a sqrt() in there somewhere.

14. Hi,

lol, no hypotenuse...I just need the solution

15. I'd also like to comment that you guys respond REALLY fast...

Popular pages Recent additions