473,972 Members | 49,766 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding sums of an html table

57 New Member
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 1501
bawa
8 New Member
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
2427
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 abc 2 abc 3
13
2715
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 one to one relationship between the two tables. I have a form for the parts. It includes 25 text boxes for both the part numbers and the quantities, so 50 total. I set the control sources for each of the part number text boxes to PartNumber...
3
4903
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 the best method? Do you have a sample of how to do this?
0
1889
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 collect the data in the Textboxes which i added dynamically from server side, i am not able to do . Alos i tried to bedug, the total no of rows in Html table does not reflect the dynamically added rows.
0
2418
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 version, the program is not working as in version 1.1. So what is the problem? Microsoft declared that the version 2.0 is fully backward support, but it is not. Is that the problem with 2.0 version? I find out the problem in version 2.0. After...
9
1561
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 in inputs: totalProp+=each print "totalProp=",totalProp
10
4424
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
2480
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 entries for . These cumulative sums will be grouped by {Planned_Close_Date] Here is what the CODE I have so far, it does not give me cumulated sums. SELECT tblDataStore.PlannedCloseDate, Count(tblDataStore.PlannedCloseDate) AS...
0
1072
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 validation but the textboxes that contain the values are not seen by the application below is my validation code Protected Sub validateTotals(ByVal source As Object, _ ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) _ ...
0
10346
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11805
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
11399
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10067
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7599
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
5143
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3749
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.