grand total

This is a discussion on grand total within the C++ Programming forums, part of the General Programming Boards category; I'm trying to find the grand total from two totals inside a loop. I'm getting some crazy numbers. Any help ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    12

    grand total

    I'm trying to find the grand total from two totals inside a loop. I'm getting some crazy numbers. Any help would be great. Thanks.

    Code:
            installCost = yards * 5;
            carpCost = yards * carpPrice;
            totalCost = installCost + padCost + carpCost;
            
            //Calculate Grand Totals
            //yards = totalYards;
          //  totalInstall = installCost;
        //    totalPad = padCost;
      //      totalCarp = carpCost;
    //        grandTotal = totalCost;
            
            totalYards += yards;
            totalInstall += installCost;
            totalPad += padCost;
            totalCarp += carpCost;
            grandTotal += totalCost;
            
            //Display output 
            cout << "Room " << roomCount << " installation = $" << installCost << endl;
            cout << "Room " << roomCount << " Padding Cost = $" << padCost << endl;
            cout << "Room " << roomCount << " Carpet Cost = $" << carpCost << endl;
            cout << "Room " << roomCount << " Total Cost = $" << totalCost << endl;
                   
            }   
    
        //Display Grand Totals
        cout << "For " << rooms << " rooms: " << endl;
        cout << "Total square yards required: " << totalYards << endl;
        cout << "Total installation: $" << totalInstall << endl;
        cout << "Total padding: $" << totalPad << endl;
        cout << "Total carpeting: $" << totalCarp << endl;
        cout << "Grand Total: $" << grandTotal << endl;

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    12
    Heres the beginning of the loop:

    Code:
      for (roomCount = 1; roomCount <= rooms; roomCount++)
        {
            cout << "Enter length for Room " << roomCount << " : ";
            cin >> length;
            cout << "Enter width for Room " << roomCount << " : ";
            cin >> width;
            cout << endl;
            cout << "1.Good - $3 per yard - [1-3 yr warrantee]" << endl;
            cout << "2.Better - $4 per yard - [3-5 yr warrantee]" << endl;
            cout << "3.Best - $5 per yard - [5-10 yr warrantee]" << endl;
            cout << "4.Excellent - $7 per yard - [10-20 yr warrantee]" << endl;
            
            //Select padding
            cout << "Enter number of padding choice <1-4>: ";
            cin >> padChoice;
            
            area = length * width;
            yards = area / 3;
                    
            switch (padChoice)
            {
                   case 1 : padCost = goodPad * yards;
                              break;
                   case 2 : padCost = betterPad * yards;
                              break;
                   case 3 : padCost = bestPad * yards;
                              break;
                   case 4 : padCost = excelPad * yards;
                              break;
                   default  : cout << "You must select 1 - 4" << endl;           
            }
            
            cout << "Enter number of carpeting per sq yd of room "<< roomCount << ": ";
            cin >> carpPrice;
            cout << "Room " << roomCount << " yards required = " << yards << endl;

Popular pages Recent additions subscribe to a feed

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