473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

adding sums of an html table

I have written the program to take input and put it in a table with negative numbers in red and positive numbers in black. The last cell in the row is used for the sum of that row. My question now is how would I go about getting the code for the columns up and down and not just across if I don't know in advance how many inputs there are? This is what I have done so far.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. cout << "<html>";
  7. cout << "<body>";
  8. cout << "<table border>";
  9.  
  10.  
  11.         int value1,value2,value3;
  12.  
  13.                 cout << "<tr><td>"<< "one"<< "</td>";
  14.                 cout << "<td>"<< "two" << "</td>";
  15.                 cout << "<td>"<< "three"<< "</td>";
  16.                 cout << "<td>"<< "Sum"<< "</td></tr>" << endl;
  17.         int sum;
  18.         int count = 1;
  19.         while (count > 0) //infinite loop that will only be broken if zero is a input.
  20.         {
  21.         cin >> value1;
  22.  
  23.                 if(value1 == 0)
  24.                 break;
  25.  
  26.                 else
  27.  
  28.                 if (value1 > 0)
  29.                 cout << "<tr><td>"<< value1<<" </td>";
  30.                 if (value1 < 0)
  31.                 cout << "<td><font color=red>" << value1 << "</font></td>";
  32.  
  33.         cin >> value2;
  34.                 if(value2 == 0)
  35.                 break;
  36.  
  37.                 else
  38.  
  39.                 if (value2 > 0)
  40.                 cout << "<td>"<< value2 << " </td>";
  41.                 if (value2 < 0)
  42.                 cout << "<td><font color=red>"<<  value2 << " </font></td>";
  43.  
  44.         cin >> value3;
  45.                 if(value3 == 0)
  46.                 break;
  47.  
  48.                 else
  49.  
  50.                 if (value3 > 0)
  51.                 cout << "<td>" << value3 <<"</td>";
  52.                 if (value3 < 0)
  53.                 cout << "<td><font color=red>" << value3 << "</font></td>";
  54.                 sum = value1 + value2 + value3;
  55.                 if (sum > 0)
  56.                 cout << "<td>" << sum << " </td>";
  57.                 else
  58.                 cout << "<td><font color=red>" << sum << "</font></td>";
  59.                 cout << "</tr>" << endl;
  60.                 count ++;
  61.  
  62.  
  63. }
  64.                 int cell = 1;
  65.                 while (cell <=3)
  66.                 {
  67.                 if (value1 == 0)
  68.                 cout << "<tr><td>" << " " << " </td>";
  69.                 cout << "<td>" << " " << " </td>";
  70.                 cout << "<td>" << " " << " </td>";
  71.                 sum = value1;
  72.                 if (sum > 0)
  73.                 cout << "<td>" << sum << " </td></tr>";
  74.                 else
  75.                 cout << "<td><font color=red>" << sum << "</font></td></tr>";
  76.                 cell++;
  77.                 break;
  78.  
  79.  
  80.  
  81.                 if (value2 == 0)
  82.                 cout << "<td>" << " " << " </td>";
  83.                 cout << "<td>" << " " << " </td>";
  84.                 sum = value1;
  85.                 if (sum > 0)
  86.                 cout << "<td>" << sum << " </td></tr>";
  87.                 else
  88.                 cout << "<td><font color=red>" << sum << "</font></td></tr>";
  89.                 cell++;
  90.                 break;
  91.  
  92.  
  93.  
  94.                 if (value3 == 0)
  95.                 cout << "<td>" << " " << " </td>";
  96.                 sum = value1+value2;
  97.                 if (sum > 0)
  98.                 cout << "<td>" << sum << " </td></tr>";
  99.                 else
  100.                 cout << "<td><font color=red>" << sum << "</font></td></tr>";
  101.                 cell++;
  102.  
  103.                 break;
  104.                 }
  105.  
  106. cout << "</html>";
  107. cout << "</body>";
  108. cout << "</table>" << endl;
  109.  
  110.         return 0;
  111.  
  112. }
ps: I know it would have been easier to use functions but the assignment didn't allow it.
Feb 21 '07 #1
1 1484
bawa
8
I have written the program to take input and put it in a table with negative numbers in red and positive numbers in black. The last cell in the row is used for the sum of that row. My question now is how would I go about getting the code for the columns up and down and not just across if I don't know in advance how many inputs there are? This is what I have done so far.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. cout << "<html>";
  7. cout << "<body>";
  8. cout << "<table border>";
  9.  
  10.  
  11.         int value1,value2,value3;
  12.  
  13.                 cout << "<tr><td>"<< "one"<< "</td>";
  14.                 cout << "<td>"<< "two" << "</td>";
  15.                 cout << "<td>"<< "three"<< "</td>";
  16.                 cout << "<td>"<< "Sum"<< "</td></tr>" << endl;
  17.         int sum;
  18.         int count = 1;
  19.         while (count > 0) //infinite loop that will only be broken if zero is a input.
  20.         {
  21.         cin >> value1;
  22.  
  23.                 if(value1 == 0)
  24.                 break;
  25.  
  26.                 else
  27.  
  28.                 if (value1 > 0)
  29.                 cout << "<tr><td>"<< value1<<" </td>";
  30.                 if (value1 < 0)
  31.                 cout << "<td><font color=red>" << value1 << "</font></td>";
  32.  
  33.         cin >> value2;
  34.                 if(value2 == 0)
  35.                 break;
  36.  
  37.                 else
  38.  
  39.                 if (value2 > 0)
  40.                 cout << "<td>"<< value2 << " </td>";
  41.                 if (value2 < 0)
  42.                 cout << "<td><font color=red>"<<  value2 << " </font></td>";
  43.  
  44.         cin >> value3;
  45.                 if(value3 == 0)
  46.                 break;
  47.  
  48.                 else
  49.  
  50.                 if (value3 > 0)
  51.                 cout << "<td>" << value3 <<"</td>";
  52.                 if (value3 < 0)
  53.                 cout << "<td><font color=red>" << value3 << "</font></td>";
  54.                 sum = value1 + value2 + value3;
  55.                 if (sum > 0)
  56.                 cout << "<td>" << sum << " </td>";
  57.                 else
  58.                 cout << "<td><font color=red>" << sum << "</font></td>";
  59.                 cout << "</tr>" << endl;
  60.                 count ++;
  61.  
  62.  
  63. }
  64.                 int cell = 1;
  65.                 while (cell <=3)
  66.                 {
  67.                 if (value1 == 0)
  68.                 cout << "<tr><td>" << " " << " </td>";
  69.                 cout << "<td>" << " " << " </td>";
  70.                 cout << "<td>" << " " << " </td>";
  71.                 sum = value1;
  72.                 if (sum > 0)
  73.                 cout << "<td>" << sum << " </td></tr>";
  74.                 else
  75.                 cout << "<td><font color=red>" << sum << "</font></td></tr>";
  76.                 cell++;
  77.                 break;
  78.  
  79.  
  80.  
  81.                 if (value2 == 0)
  82.                 cout << "<td>" << " " << " </td>";
  83.                 cout << "<td>" << " " << " </td>";
  84.                 sum = value1;
  85.                 if (sum > 0)
  86.                 cout << "<td>" << sum << " </td></tr>";
  87.                 else
  88.                 cout << "<td><font color=red>" << sum << "</font></td></tr>";
  89.                 cell++;
  90.                 break;
  91.  
  92.  
  93.  
  94.                 if (value3 == 0)
  95.                 cout << "<td>" << " " << " </td>";
  96.                 sum = value1+value2;
  97.                 if (sum > 0)
  98.                 cout << "<td>" << sum << " </td></tr>";
  99.                 else
  100.                 cout << "<td><font color=red>" << sum << "</font></td></tr>";
  101.                 cell++;
  102.  
  103.                 break;
  104.                 }
  105.  
  106. cout << "</html>";
  107. cout << "</body>";
  108. cout << "</table>" << endl;
  109.  
  110.         return 0;
  111.  
  112. }
ps: I know it would have been easier to use functions but the assignment didn't allow it.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void main() 
  5. {
  6.  
  7.     int value[100];    
  8.     int sum=0;
  9.     int count; 
  10.  
  11.     cout << endl << "Kindly enter the number of inputs" <<endl;
  12.     cin >> count;
  13.  
  14.     cout << endl << "Kindly enter the values for the specified number of inputs" << endl;
  15.     for(int i=0;i<count;i++)
  16.     cin >> value[i];
  17.  
  18.     cout << endl << endl;
  19.     cout << "<html>";
  20.     cout << "\n";
  21.     cout << "<body>";
  22.     cout << "\n\t";
  23.     cout << "<table border>";    
  24.  
  25.  
  26.     i=0;    
  27.     while (i < count)
  28.     {
  29.  
  30.         if(value[i] == 0)
  31.         break;
  32.  
  33.         else
  34.  
  35.             if (value[i] > 0)
  36.             cout << endl << "\t\t" << "<tr>" << "\n\t\t\t" <<"<td> value" << i << "</td>" << "\n\t\t\t" << "<td>" << value[i] << "</td>" <<"\n\t\t" <<"</tr>";
  37.             if (value[i] < 0)
  38.             cout << endl << "\t\t" << "<tr>" << "\n\t\t\t" <<"<td> value" << i << "</td>" << "\n\t\t\t" <<"<td><font color=red>" << value[i] << "</font></td>" <<"\n\t\t" <<"</tr>";
  39.  
  40.         sum = sum + value[i];
  41.         i++;
  42.     }
  43.  
  44.  
  45.     if (sum > 0)
  46.     cout << endl << "\t\t" << "<tr>" << "\n\t\t\t" <<"<td> Sum </td>" <<"\n\t\t\t"  <<"<td>" << sum << "</td>" <<"\n\t\t" <<"</tr>";
  47.     else
  48.     cout << endl << "\t\t" << "<tr>" << "\n\t\t\t" <<"<td> Sum </td>" <<"\n\t\t\t"  <<"<td><font color=red>" << sum << "</font></td>" <<"\n\t\t" <<"</tr>";
  49.  
  50.  
  51.     cout << "\n\t";
  52.     cout << "</table>" << endl;
  53.     cout << "</html>" <<endl;
  54.     cout << "</body>" <<endl;
  55.  
  56. }
  57.  

Hope this will solve ur problem..

- Bawa
Feb 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Jamie Fryatt | last post by:
Hi everyone, here's what id like to do. I have a table with 2 fields, name and value I need to be able to add multiple records quickly, for example I need to add name value abc 1...
13
by: Shannan Casteel via AccessMonster.com | last post by:
I set up two tables (one with the regular claim info and another with ClaimNumber, PartNumber, and QuantityReplaced). The ClaimNumber is an autonumber and the primary key in both tables. I made a...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
0
by: Sileesh | last post by:
Hi I have html table and a Button in an Aspx page. I am adding one row with some textboxes to Html table each time i click on the Button thru Javascript. Now problem is when when i try to...
0
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta...
9
by: joanne matthews (RRes-Roth) | last post by:
I'm getting different results when I add up a list of floats depending on the order that I list the floats. For example, the following returns False: def check(): totalProp=0 inputs= for each...
10
by: =?Utf-8?B?Q2hyaXMgRy4=?= | last post by:
How would I output a row for the Computed sums? I just want to append it as a row at the bottom of my gridview table.
1
by: wisemen | last post by:
I have a table with 2 columns, and .I want to run a query that will give me a cumulative sum of the no. of entries that have an <= and on the second column give me a cumulative sum of the no. of...
0
by: Garudzo | last post by:
I am developing an application using the gridview. the last column is a total column I want to compare the typed in value to the sum of values in the rest of the cells. I tried to use custom...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.