One more thing...

This is a discussion on One more thing... within the C++ Programming forums, part of the General Programming Boards category; To all of those who are im sure sick of me and all my questions, heres one more. Here is ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    29

    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
    Talitore - Using DEV-C++

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    What errors are you getting?
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    29
    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
    Talitore - Using DEV-C++

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    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.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    29
    I now but like i said im new at this

    but thanks ill try it.
    Talitore - Using DEV-C++

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    29
    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
    Talitore - Using DEV-C++

  8. #8
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    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 {}
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    29
    ahh thanks ill get back to you with the results
    Talitore - Using DEV-C++

  11. #11
    Registered User
    Join Date
    Oct 2002
    Posts
    29
    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!!
    Talitore - Using DEV-C++

  12. #12
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  13. #13
    Registered User
    Join Date
    Oct 2002
    Posts
    29
    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!!!
    Talitore - Using DEV-C++

  14. #14
    Registered User
    Join Date
    Oct 2002
    Posts
    29
    can anyone help?
    Talitore - Using DEV-C++

  15. #15
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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 .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pause/idle thing
    By freedik in forum Windows Programming
    Replies: 13
    Last Post: 08-22-2003, 09:46 AM
  2. A very strange thing
    By gustavosserra in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2003, 12:43 PM
  3. most challenging thing to program
    By volk in forum A Brief History of Cprogramming.com
    Replies: 52
    Last Post: 03-28-2003, 02:56 PM
  4. newbie needs help comprehending simple thing
    By A helpless one in forum C++ Programming
    Replies: 6
    Last Post: 12-16-2002, 08:23 PM
  5. PingPong But how to make 2 thing at the same time..
    By Gugge in forum C Programming
    Replies: 5
    Last Post: 04-02-2002, 05:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21