# Thread: One more thing...

1. ## One more thing...

To all of those who are im sure sick of me and all my questions, heres one more.

Here is my program, remember this is my first menu type and i am getting errors compiling it. Could some help me out?

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

int main()

{
int resp, x, a;
float num, val;
char num2, cont;

for(;;)
x = 0;
{
cout << "            Conversion Program" << endl;
cout << "            ==================" << endl;
cout << "    Option  Description" << endl;
cout << "    ------  ---------------------" << endl;
cout << "       0    Quit" << endl;
cout << "       1    Binary - Decimal" << endl;
cout << "       2    Decimal - Binary" << endl;
cout << "       Please choose an option." << endl;

cin >> resp;

if (resp == 0)

break;

switch(resp)
{
case 1:
cout << "Binary - Decimal..." << endl;
cout << "Enter the number needing converting:" << endl;
cin << num;

Val = (Num / 10000000.0);
if(Val >= 1.0)
{
cout << "Has to be under 8 numbers long!" << endl;
break;
}

else
a= num % 10;
if (a = 1)
{
x = x + 1;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 2;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 8;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 16;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 32;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 64;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 128;
}

cout << "The number in Decimal is: " << x;
break;

case 2:
cout << "Decimal - Binary..." << endl;
cout << "Enter the number needing converting:" << endl;
cin << num;
if (num > 255)
{
cout << "Number cannot be larger than 255!" << endl;
break;
}

if (num >= 1)
{
num = num - 1;
x = x + 1;
}

if  (num >= 2)
{
num = num - 2;
x = x + 10;
}

if  (num >= 4)
{
num = num - 4;
x = x + 100;
}

if  (num >= 8)
{
num = num - 8;
x = x + 1000;
}

if  (num >=16)
{
num = num - 16;
x = x + 10000;
}

if  (num >= 32)
{
num = num - 32;
x = x + 100000;
}

if  (num >= 64)
{
num = num - 64;
x = x + 1000000;
}

if  (num >= 128)
{
num = num - 128;
x = x + 10000000;
}

cout << "The number in Binary is: " << x;
break;

default;
cout << "Invalid Response!!" << endl;
break;

cout << "Type a 'c' to continue..." << endl;
cin >> cont;
}
return 0;
}```
Thanks

2. What errors are you getting?

3. oh sorry, lots of 'em ill try to list them all.

[warning] in function 'int main()':

break statement not within loop or switch: line 26

no match for _io_Stream_withassign & << float &': line 34, 104

invalid operands 'float' and 'int' to binary 'operator %': lines 44,52,60,68,76,84,92

parse error before';': line 162

parse error at end of input:171

Thanks

4. ## Re: One more thing...

Originally posted by tkems
Code:
```#include <iostream.h>

int main()

{
int resp, x, a;
float num, val;
char num2, cont;

for(;;)
x = 0; //(Setting x to 0 forever?)
{
cout << "            Conversion Program" << endl;
cout << "            ==================" << endl;
cout << "    Option  Description" << endl;
cout << "    ------  ---------------------" << endl;
cout << "       0    Quit" << endl;
cout << "       1    Binary - Decimal" << endl;
cout << "       2    Decimal - Binary" << endl;
cout << "       Please choose an option." << endl;

cin >> resp;

if (resp == 0)

break;

switch(resp)
{
case 1:
cout << "Binary - Decimal..." << endl;
cout << "Enter the number needing converting:" << endl;
cin << num;

Val = (Num / 10000000.0);
if(Val >= 1.0)
{
cout << "Has to be under 8 numbers long!" << endl;
break;
}

else
a= num % 10; //Cannot do a (int % float)
if (a = 1) //(a == 1)
{
x = x + 1;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 2;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 8;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 16;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 32;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 64;
}

num2 = num2 / 10;

a= num % 10;
if (a = 1)
{
x = x + 128;
}

cout << "The number in Decimal is: " << x;
break;

case 2:
cout << "Decimal - Binary..." << endl;
cout << "Enter the number needing converting:" << endl;
cin << num;
if (num > 255)
{
cout << "Number cannot be larger than 255!" << endl;
break;
}

if (num >= 1)
{
num = num - 1;
x = x + 1;
}

if  (num >= 2)
{
num = num - 2;
x = x + 10;
}

if  (num >= 4)
{
num = num - 4;
x = x + 100;
}

if  (num >= 8)
{
num = num - 8;
x = x + 1000;
}

if  (num >=16)
{
num = num - 16;
x = x + 10000;
}

if  (num >= 32)
{
num = num - 32;
x = x + 100000;
}

if  (num >= 64)
{
num = num - 64;
x = x + 1000000;
}

if  (num >= 128)
{
num = num - 128;
x = x + 10000000;
}

cout << "The number in Binary is: " << x;
break;

default;
cout << "Invalid Response!!" << endl;
break;

cout << "Type a 'c' to continue..." << endl;
cin >> cont;
}
return 0;
}```
Big parts of your program could've been better made using loops instead of lots of code chunks.

5. I now but like i said im new at this

but thanks ill try it.

6. Originally posted by tkems
I now but like i said im new at this

but thanks ill try it.
Did you notice my notes in your code? (marked with red).

7. Ok. so far so good, alot has been fixed.
Yes i want X to equal 0.

I change something so that "num % 10" is not a "int % float."

It is still saying:
break statement not within a loop or switch: line 27, 166

no match for _IO_Stream_withassign & << int &': line 35, 105

parse error before";": line 164

Thanks

8. Originally posted by tkems
Ok. so far so good, alot has been fixed.
Yes i want X to equal 0.
But you don't want the operation "x=0" to be executed forever, do you?
One time is enough per loop, put that statement inside the {}

9. Of course. Your first error (in red).
As I said, you're setting x to 0 an infinite number of times. You may want to move that x=0; either outside the loop, or inside the brackets ( the { and } ).

Since you're looping the assignment and not the brackets, your break statement is placed outside the loop, thus the error.

10. ahh thanks ill get back to you with the results

11. Ok thanks im down to 3 errors

no match for _IO_Stream_withassign & << int &': line 35, 105

parse error before";": line 164

Thanks so much!!

12. cin << num; (on both rows)

default;

I suggest you train in finding simple syntax errors like this on your own, since it will help you very much and save valuable time . The compiler tells you on which row the error is (+/- 1) so it shouldn't be too hard to find them.

13. im still getting 2 errors though. Ive made all the changes you said to and i still get these:

parse error before ';': line 163

parse error at end of input: line 172

please help!!!

14. can anyone help?

15. Have a look at those lines for syntac errors. Missing ; and such.
I also suggest you count your { versus your } and see if you find something strange there .

Popular pages Recent additions