### Need help debugger says im missing }.

/code

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int index;
double input1, input2, input3, output;
bool quit, back, back2;

do
{
cout << "0. Quit\n";
cout << "1. Unit Convertion\n";
cout << "2. Four Operations\n";
cout << "3. Math Functions\n";
quit = false;
cin >> index;

switch(index)
{
case 0:
quit = true;
break;
case 1:
do
{
cout << "0. Back to Menu\n";
cout << "1. Length\n";
cout << "2. Mass\n";
cout << "3. Velocity\n";
cout << "4. Force\n";
cout << "5. Pressure\n";
back = false;
cin >> index;

default:
break;
switch(index)
{
case 0:
back = true;
break;

case 1:

cout << "0. Back\n";
cout << "1. (in) to (m)\n";
cout << "2. (m) to (in)\n";
back = false;
cin >> index;
case 2:
cout << "0. Back\n";
cout << "3. (kg) to (lbs)\n";
cout << "4. (lbs) to (kg)\n";
back = false;
cin >> index;
case 3:
cout << "0. Back\n";
cout << "5. (mi/hr) to (km/hr)\n";
cout << "6. (km/hr) to (mi/hr)\n";
back = false;
cin >> index;
case 4:
cout << "0. Back\n";
cout << "7. (N) to (lbf)\n";
cout << "8. (lbf) to (N)\n";
back = false;
cin >> index;

case 5:
cout << "0. Back\n";
cout << "9. (Pa) to (psi)\n";
cout << "10. (psi) to (Pa)\n";
back = false;
cin >> index;

default:
break;

}
switch(index)
{
case 0:
back2 = true;
break;
case 1:
cout << "Enter a length:\n";
cin >> input1;
output = input1 * 25.4/1000;
cout << "It equals " << output << " m\n";
break;

case 2:
cout << "Enter a length:\n";
cin >> input1;
output = input1 * 39.3701;
cout << "It equals " << output << " in\n";
break;

case 3:
cout << "Enter a mass:\n";
cin >> input1;
output = input1 * 2.205;
cout << "It equals " << output << " lb\n";
break;
case 4:
cout << "Enter a mass:\n";
cin >> input1;
output = input1 * 0.4536;
cout << "It equals " << output << " kg\n";
break;

case 5:
cout << "Enter a velocity:\n";
cin >> input1;
output = input1 * 0.6214;
cout << "It equals " << output << " km/hr\n";
break;

case 6:
cout << "Enter a velocity:\n";
cin >> input1;
output = input1 * 1.61;
cout << "It equals " << output << " mi/hr\n";
break;

case 7:
cout << "Enter a force:\n";
cin >> input1;
output = input1 * 0.225;
cout << "It equals " << output << " lbf\n";
break;

case 8:
cout << "Enter a force:\n";
cin >> input1;
output = input1 * 4.45;
cout << "It equals " << output << " N\n";
break;

case 9:
cout << "Enter a pressure:\n";
cin >> input1;
output = input1 * .000145;
cout << "It equals " << output << " psi\n";
break;

case 10:
cout << "Enter a pressure:\n";
cin >> input1;
output = input1 * 6894.76;
cout << "It equals " << output << " Pa\n";
break;
}
} while(back != true);
break;
case 2:
do
{
cout << "0. Back to Menu\n";
cout << "2. Subtraction\n";
cout << "3. Multiplication\n";
cout << "4. Division\n";

back = false;
cin >> index;

switch(index)
{
case 0:
back = true;
break;

case 1:
cout << "0. Back\n";
cout << "1. Enter two numbers to add\n";
cin >> input1 >> input2;
output = input1 + input2;
cout << output;
back = false;
cin >> index;

case 2:
cout << "0. Back\n";
cout << "1. Enter two numbers to subtract\n";
cin >> input1 >> input2;
output = input1 - input2;
cout << output;
back = false;
cin >> index;

case 3:
cout << "0. Back\n";
cout << "1. Enter two numbers to multiply\n";
cin >> input1 >> input2;
output = input1 * input2;
cout << output;
back = false;
cin >> index;

case 4:

cout << "0. Back\n";
cout << "1. Enter two numbers to divide\n";
cin >> input1 >> input2;
output = input1/input2;
cout << output;
back = false;
cin >> index;

}
} while(back != true);
break;

case 3:
do
{
cout << "0. Back to Menu\n";
cout << "1. Absolute value\n";
cout << "2. Square Root\n";
cout << "3. Power\n";
cout << "4. Exponential function\n";
cout << "5. log\n";
cout << "6. log base 10\n";
cout << "7. sine\n";
cout << "8. cosine\n";
cout << "9. tangent\n";
cout << "10. arc sine\n";
cout << "11. arc cosine\n";
cout << "12. arc tangent\n";
cout << "13. arc tangent with two arguments\n";
cout << "14. Hyperbolic sine function\n";
cout << "15. Hyperbolic cosine function\n";
cout << "16. Hyperbolic tangent function\n";
cout << "17. ceiling function\n";
cout << "18. floor function\n";
back = false;
cin >> index;
switch(index)
{
case 0:
back = true;
break;
case 1:
cout << "0. Back\n";
cout << "1. Enter a number to get absolute value\n";
cin >> input1;
output = abs(input1);
cout << output;
back = false;
cin >> index;
case 2:
cout << "0. Back\n";
cout << "1. Enter a number to get square root\n";
cin >> input1;
output = sqrt(input1);
cout << output;
back = false;
cin >> index;
case 3:
cout << "0. Back\n";
cout << "1. Enter a number and to what power you would like it\n";
cin >> input1 >> input2;
output = pow(input1,input2);
cout << output;
back = false;
cin >> index;

case 4:
cout << "0. Back\n";
cout << "1. Enter a number for e to the power of\n";
cin >> input1;
output = exp(input1);
cout << output;
back = false;
cin >> index;
case 5:
cout << "0. Back\n";
cout << "1. Enter a number you would like the log of\n";
cin >> input1;
output = log(input1);
cout << output;
back = false;
cin >> index;
case 6:
cout << "0. Back\n";
cout << "1. Enter a number you would like to get to the log base 10\n";
cin >> input1;
output = log10(input1);
cout << output;
back = false;
cin >> index;
case 7:
cout << "0. Back\n";
cout << "1. Enter a number to get sine of\n";
cin >> input1;
output = sin(input1);
cout << output;
back = false;
cin >> index;

case 8:

cout << "0. Back\n";
cout << "1. Enter a number to get the cosine of\n";
cin >> input1;
output = cos(input1);
cout << output;
back = false;
cin >> index;

case 9:

cout << "0. Back\n";
cout << "1. Enter a number to get the tangent of\n";
cin >> input1;
output = tan(input1);
cout << output;
back = false;
cin >> index;

case 10:

cout << "0. Back\n";
cout << "1. Enter a number to get arc sine of\n";
cin >> input1;
output = asin(input1);
cout << output;
back = false;
cin >> index;

case 11:

cout << "0. Back\n";
cout << "1. Enter a number to get arc cosine of\n";
cin >> input1;
output = acos(input1);
cout << output;
back = false;
cin >> index;

case 12:

cout << "0. Back\n";
cout << "1. Enter a number to get arc tangent of\n";
cin >> input1;
output = atan(input1);
cout << output;
back = false;
cin >> index;

case 13:

cout << "0. Back\n";
cout << "1. Enter a number to get the arc tangent double argument of\n";
cin >> input1, input2;
output = atan2(input1,input2);
cout << output;
back = false;
cin >> index;

case 14:

cout << "0. Back\n";
cout << "1. Enter a number to get the hyperbolic function of sine of\n";
cin >> input1;
output = sinh(input1);
cout << output;
back = false;
cin >> index;

case 15:

cout << "0. Back\n";
cout << "1. Enter a number to get the hyperbolic function of cosine\n";
cin >> input1;
output = cosh(input1);
cout << output;
back = false;
cin >> index;

case 16:

cout << "0. Back\n";
cout << "1. Enter a number to get the hyperbolic function of tangent\n";
cin >> input1;
output = tanh(input1);
cout << output;
back = false;
cin >> index;

case 17:

cout << "0. Back\n";
cout << "1. Enter a number to get the ceiling function of\n";
cin >> input1;
output = ceil(input1);
cout << output;
back = false;
cin >> index;

case 18:

cout << "0. Back\n";
cout << "1. Enter a number to get the floor fucntion of\n";
cin >> input1;
output = floor(input1);
cout << output;
back = false;
cin >> index;

default:
break;
}

}while(back != true);
break;

}while(quit != true);

system("pause");
return 0;

}
/code
Last edited on
You need to post something more substantial than simply: 'Need Help with Menu'. Not enough information is given. What menu? Please elaborate. Also, mark your source code with code, /code tags.
It says im missing a } but im not sure where to put one.
Hi dean93,

Apart from code tags (use the <> button on the format menu) and proper indenting which will help identify the missing brace, the most obvious thing is the desperate need for more functions in your code.

If you have compiler errors, then post them in full here - we can explain it to you.

If you use an IDE, then it should do braces, parentheses etc automatically.

There is an unwritten rule about having a maximum of 40 LOC per function. Some candidates for functions are the code in you switch cases.

Lots of your cases are very similar - can you figure out how to write 1 short function that does the same thing?

Here is some psuedo code as a clue:

 ``12345`` ``````// Show the menu text - should be a void function // Get input : Operation Type sin cos tan etc // Get Input : The number // Carry out the correct operation // show results ``````

Whenever you find yourself writing similar code over & over, then you probably need a function.

To give you an idea - this code could be written with less than 30 LOC.

With `switch`s, almost always put a `break;` after each `case`, and always provide a default case to catch bad input.

I have a personal vendetta against `do` loops - Did you know that all 3 types of loops can be rewritten into 1 of the other forms. In this case I would use a `while` loop.

Have a read of the tutorial at the top left of this page, there is also heaps of reference materials & articles.

Hope all goes well:+)

Edit:

Also realise the difference between compiling & debugging. Debugging is the ability to run through an executable program 1 line at a time and keep an eye on the value of variables to detect logical errors. Compiling just finds syntax errors in your code.
Last edited on
We haven't learned functions just yet. Also the professor started the layout i was just finish it with the extra cases.
Ok, can you post your code with code tags, and post the compiler error in full.

Edit:
What was the exact text of the assignment, and the original code? I am having trouble with the idea that the prof would promote such programming. Even without functions it could be much shorter. Have a close look at the pseudo code I posted.
Last edited on
The assignment was to create a menu user interface to convert units, calculate math functions, and to calculate operations. This is the code he posted. Thanks for the help.

code\
#include <iostream>
#include <cmath>
using namespace std;

int main()
{

int index;
double input1, input2, input3, output;
bool quit, back, back2;

do
{
cout << "0. Quit\n";
cout << "1. Unit Convertion\n";
cout << "2. Four Operations\n";
cout << "3. Math Functions\n";
quit = false;
cin >> index;

switch(index)
{

case 0:
quit = true;
break;

case 1:
do
{
cout << "0. Back to Pervious Menu\n";
cout << "1. Length\n";
cout << "2. Mass\n";
cout << "3. Velocity\n";
cout << "4. Force\n";
cout << "5. Pressure\n";
back = false;
cin >> index;

switch(index)
{

case 0:
back = true;
break;

case 1:

do
{

cout << "0. Back\n";
cout << "1. from inches(in) to meters(m)\n";
cout << "2. from meters(m) to inches(in)\n";
back = false;
cin >> index;

switch(index)
{
case 0:
back2 = true;
break;

case 1:
cout << "Enter a length:\n";
cin >> input1;
output = input1 * 25.4/1000;
cout << "It equals " << output << " m\n";
break;
}
}while(back2 != true);
}while(back != true);
break;

case 2:
break;

case 3:
break;

default:
break;
}
}while(quit != true);

system("pause")
return 0;
}

\code

code tags:

Edit your posts (all of them)
Press the
 <>
button on the format menu on the right

Using code tags will format it properly - you might be able to see where the missing brace is. If you use an IDE it will be obvious.

Post the compiler error in full- it will tell you & us where the missing brace is.

If your prof wants you all to code like this then there isn't much advice we can give really.
Seems like you didn't close off your outermost `switch` statement:
 ``123456789`` `````` }while(back != true); break; // Missing curly brace here }while(quit != true); system("pause"); return 0; }``````
Thanks for the help
Topic archived. No new replies allowed.