Looping program

Discussion in 'Software' started by debuggit, Feb 26, 2008.

  1. debuggit

    debuggit Private E-2

    I need to:
    1. receive integer input from the user
    2. create an html table - three inputs per row, the fourth column summing the row
    3. negative integers must display in red
    4. if the user enters zero, the row in play blanks out and all columns are summed

    My table displays fine. The first row is perfect. Then things go haywire.
    Does anyone have any advice or solutions?

    Thanks!

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    
    //declare variables
    
    int number = 0;
    int num1 = 0, num2 = 0, num3 = 0;
    int num1_total = 0, num2_total = 0, num3_total = 0;
    int num_sum = num1 + num2 + num3;
    int sum_total = 0;
    int num_count = 0;
    bool end_sum = false;
    bool end_row = false;
    "table.cpp" 123L, 3592C                                       1,1           Top
    // Construct an integer table
    
    int num_count = 0;
    {
             end_sum = true;
             end_row = true;
             switch (num_count) //if the input equals zero, all equal zero, print table 
             {
                case 1:  num1 = 0;
                break;
                case 2:  num2 = 0;                                                                   
    
                                                                                                     
    
                           
                break;                                                                               
    
                                                                                                     
    
                           
                }                                                                                    
    
                                                                                                     
    
                           
          if (number != 0) //if the input is not zero read 3 inputs into the table row               
    
                                                                                                     
    
                           
          {
             cout << "<tr>" << endl;
             cout << "<td>" << num1 << "</td> <td>" << num2 << "</td> <td>" << num3 << "</td> <td>" 
    
    << "</td> <td>" << num_sum << "</td> <td>" << endl;                                              
    
                            
             cout << "</tr>" << endl;
         
          if (number < 0) //if input is less then zero print with red font 
          {
             cout << "<tr>" << endl;
             cout << "<td><font color=FF0000>" << num1 << "</td>" << num2 << "</td>" << num3 << 
    
    "</font></td>" "<td>" << num_sum << "</td> <td>" << endl;                                        
    
                                
             cout << "</tr>" << endl;
          }
          }
          }
          
          else // not the end of the row 
          {
             num_count++;
             switch (num_count) //assign three input values to variable names                        
    
                                                                                                     
    
                           
             {
                case 1: num1 = number;                                                               
    
                                                                                                     
    
                           
                        num1_total += num1;
                        break;                                                                       
    
                                                                                                     
    
                           
                case 2: num2 = number;
                        num2_total += num2;                                                          
    
                                                                                                     
    
                           
                        break;
                case 3: num3 = number;                                                               
    
                                                                                                     
    
                           
                        num3_total += num3;
                        break;                                                                       
    
                                                                                                     
    
                           
                case 4: num_sum = num1 + num2 + num3;
                        break;                                                                       
    
                                                                                                     
    
                           
                case 5: sum_total += num_sum;
                        end_row = true;                                                              
    
                                                                                                     
    
                           
                        break;
                default: end_row = true;                                                             
    
                                                                                                     
    
                           
                         break;
             }
          }
       }
    
       else //end of input print table 
       {
          cout << "<tr>" << endl;
          cout << "<td>" << num1 << "</td><td>" << num2 << "</td><td>" << num3 << "</td><td>" << 
    
    num_sum << "</td><td>" << endl;                                                                  
    
                               
          cout << "</tr>" << endl;
          cout << "<tr>" << num1_total << "</td><td>" << num2_total << "</td><td>" << num3_total << 
    
    "</td><td>" << sum_total << "</td><td>" << endl;                                                 
    
                            
          end_row = false;                                                                           
    
                                                                                                     
    
                           
          num_count = 0; }                                                                           
    
                                                                                                     
    
                           
    
       //end of user input                                                                           
    
                                                                                                     
    
                           
       }
    
    cout << "</table>" << endl;                                                                      
    
                                                                                                     
    
                           
    cout << "You may view the table now.";                                                           
    
                                                                                                     
    
                           
    
    return 0;
    
    }
    
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds