Thread: why wont this work??

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by ammochck21 View Post
    when i read in the size and printed out to see what its reading in...it only prints an M.....the spaces get skipped with what we are doing....so its not really going through the for loop until i = 3.....
    Did you remove the semicolon after the for loop?

  2. #17
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    ok here is the whole code I have written.....this wont work for the commented out parts:

    Code:
    cin >> jobnum;
    while (!cin.eof())
    {
      cin >> code;
      while(code!='Q')
        {
       if (code == 'P')
            {
              cin >> num;
              for (int i=1; i <= num; i++);
               {
                cin >> size;
                if (size == 'S')
                 {
                  total1 = total1 + S;
                 }
                else if (size == 'M')
                 {
                  total1 = total1 + M;
                 }
                else if (size == 'L')
                 {
                  total1 = total1 + L;
                 }
               }
            }
    
           else if (code == 'R')
            {
              cin >> num;
              total2 = total2 + (num* REMOVAL);
            }
    
           else if (code == 'T')
            {
             cin >> trimnum;
             total3 = total3 + (trimnum * TRIM);
            }
    
    
       /*  else if (code == 'S')                  *this wont work when uncommented...stays in infinite loop
            {
             cin >> num;
             for (int j =1; j <= num; j++)
              {
               cin >> diam;
               if (diam <=10)
                {
                 total4 = total4 + 75;
                }
               else if (diam > 10)
                {
                 total4 = total4 + (diam * 10);
                }
              }
            }
       */
    
       cin >> code;
      }
    
     sum1 = total1 + total2 + total3 + total4;
    
     cout << jobnum << "      $" << right << setw(7) << total1 << "    $" << setw(8) << total2 << "    $" << setw(8) << total3 << "   $" << setw(10) << total4 << "   $" << setw(10) \
    << sum1 << endl;
    
     total1 = 0.0;
     total2 = 0.0;
     total3 = 0.0;
     total4 = 0.0;
    
     cin >> jobnum;
     }
     cout <<  "TOTAL" << setw (65) << sum <<  endl;   ////////need to fix this
    }

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So: no you didn't remove the semicolon. You should do so.

    The problem with your S loop is that it's finding your S for a size, and the reading gets out of whack. It's still not an infinite loop though, since num must have a value even if you read it in.

  4. #19
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    I cant BELIEVE it was that tiny little thing!!!!!! THANK YOU!!!!!!!!!!!!!!!!! It works now!

  5. #20
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    so what do i need to do for the S loop...i see what your saying...but i dont know what to do to fix it...i ran through it by hand...and it worked...but I am also not a computer... thanks!

  6. #21
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    for the S input...it will read te first number which tells it how many sizes it need to read in.

    So for S 5 12 3 10 7 16

    it reads in num which is 5.
    it should go through the for loop 5 times...reading in the diameters after it.....

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There's nothing wrong with your S loop.

    The condition after the else is redundant, but it still works.

  8. #23
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    ok well your right it works now...i dont know if removing the semicolon made it work but it does.

    i now have to add all of the sum's to get a final total...any suggestions?



    Job# Planting Removal Trimming Removal Billed
    123 $ 235 $ 0 $ 187.5 $ 0 $ 422.5
    456 $ 500 $ 2000 $ 0 $ 505 $ 3005

    TOTAL 0 <--- this is where i need to add the 422.5 and the 3005.

  9. #24
    Registered User
    Join Date
    Nov 2006
    Posts
    85
    I got it...nevermind thanks so much!!!

  10. #25
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Keep a running total that you don't zero out at the start of every new job.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 12:39 PM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM