473,320 Members | 2,110 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,320 software developers and data experts.

question on c++ program to make an html table

I am writing a program that can take input from a user or file of positive and negative numbers. Then display them in a html table. The negative numbers have to be outputted in red html font on the table and the positive numbers will just be outputted. I wrote a loop that shouldn't terminate till a zero is entered. For some reason it won't print my table. This is what I have so far if anyone can shine some light on this for me I would be gratefull.
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>";
  9.  
  10.     int value1,value2,value3;
  11.  
  12.     cout << "<tr><td>"<< "1"<< "</td>";
  13.     cout << "<td>"<< "2" << "</td>";
  14.     cout << "<td>"<< "3"<< "</td>";
  15.     cout << "<td>"<< "Sum"<< "</td></tr>" << endl;
  16.     int sum;
  17.     int count = 1;
  18.     while (count > 0) //infinite loop that will only be broken if zero is a input.
  19.     {
  20.         cin >> value1 >> value2 >> value3;
  21.         while(value1 == 0)
  22.         {
  23.             cout << "<tr><td>" << " " << " </td>";
  24.             cout << "<td>" << " " << " </td>";
  25.             cout << "<td>" << " " << " </td>";
  26.             sum = value1;
  27.             cout << "<td>" << sum << " </td>";
  28.             cout << "</tr>";
  29.         }
  30.         break;
  31.         if (value1 > 0)
  32.             cout << "<tr><td>"<< value1<<" </td>";
  33.         else;
  34.             cout << "<td><font color=red>" << value1 << "</font></td>";
  35.  
  36.         while(value2 == 0)
  37.         {
  38.             cout << "<td>" << " " << " </td>";
  39.             cout << "<td>" << " " << " </td>";
  40.             sum = value1+value2;
  41.             cout << "<td>" << sum << " </td>";
  42.             cout << "</tr>";
  43.         }
  44.         break;
  45.  
  46.         if (value2 > 0)
  47.             cout << "<tr><td>"<< value2 << " </td>";
  48.         else;
  49.         cout << "<td><font color=red>"<<  value2 << " </font></td>";
  50.  
  51.         while(value3 == 0)
  52.         {
  53.              cout << "<td>" << " " << " </td>";
  54.              sum = value1+value2+value3;
  55.              cout << "<td>" << sum << " </td>";
  56.              cout << "</tr>";
  57.          }
  58.          break;
  59.  
  60.          if (value3 > 0)
  61.              cout << "<tr><td>" << value3 <<"</td>";
  62.          else;
  63.          cout << "<td><font color=red>" << value3 << "</font></td>";
  64.          sum = value1 + value2 + value3;
  65.          cout << "<td>" << sum << " </td>";
  66.          cout << "</tr>" << endl;
  67.     }
  68.     cout << "</html>";
  69.     cout << "</body>";
  70.     cout << "</table>" << endl;
  71.  
  72.     return 0;
  73.  
  74. }
Feb 21 '07 #1
1 3387
sicarie
4,677 Expert Mod 4TB
I am writing a program that can take input from a user or file of positive and negative numbers. Then display them in a html table. The negative numbers have to be outputted in red html font on the table and the positive numbers will just be outputted. I wrote a loop that shouldn't terminate till a zero is entered. For some reason it won't print my table. This is what I have so far if anyone can shine some light on this for me I would be gratefull.
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>";
  9.  
  10.     int value1,value2,value3;
  11.  
  12.     cout << "<tr><td>"<< "1"<< "</td>";
  13.     cout << "<td>"<< "2" << "</td>";
  14.     cout << "<td>"<< "3"<< "</td>";
  15.     cout << "<td>"<< "Sum"<< "</td></tr>" << endl;
  16.     int sum;
  17.     int count = 1;
  18.     while (count > 0) //infinite loop that will only be broken if zero is a input.
  19.     {
  20.         cin >> value1 >> value2 >> value3;
  21.         while(value1 == 0)
  22.         {
  23.             cout << "<tr><td>" << " " << " </td>";
  24.             cout << "<td>" << " " << " </td>";
  25.             cout << "<td>" << " " << " </td>";
  26.             sum = value1;
  27.             cout << "<td>" << sum << " </td>";
  28.             cout << "</tr>";
  29.         }
  30.         break;
  31.         if (value1 > 0)
  32.             cout << "<tr><td>"<< value1<<" </td>";
  33.         else; 
  34.         cout << "<td><font color=red>" << value1 << "</font></td>";
  35.  
  36.         while(value2 == 0)
  37.         {
  38.             cout << "<td>" << " " << " </td>";
  39.             cout << "<td>" << " " << " </td>";
  40.             sum = value1+value2;
  41.             cout << "<td>" << sum << " </td>";
  42.             cout << "</tr>";
  43.         }
  44.         break;
  45.  
  46.         if (value2 > 0)
  47.             cout << "<tr><td>"<< value2 << " </td>";
  48.         else;
  49.         cout << "<td><font color=red>"<<  value2 << " </font></td>";
  50.  
  51.         while(value3 == 0)
  52.         {
  53.              cout << "<td>" << " " << " </td>";
  54.              sum = value1+value2+value3;
  55.              cout << "<td>" << sum << " </td>";
  56.              cout << "</tr>";
  57.          }
  58.          break;
  59.  
  60.          if (value3 > 0)
  61.              cout << "<tr><td>" << value3 <<"</td>";
  62.          else;
  63.          cout << "<td><font color=red>" << value3 << "</font></td>";
  64.          sum = value1 + value2 + value3;
  65.          cout << "<td>" << sum << " </td>";
  66.          cout << "</tr>" << endl;
  67.     }
  68.     cout << "</html>";
  69.     cout << "</body>";
  70.     cout << "</table>" << endl;
  71.  
  72.     return 0;
  73.  
  74. }
You use breaks after the inner while loops - that pulls you out, no matter what (I think you might want an if statement - if the first while loop was entered, then break...). Also, I'm not sure if you mean to have those ';'s after the else statements - they signify that the else is empty and the cout statements after that will be run, even if the else condition is not met (just in case that was not by design - I have seen that used, and used it myself before).
Feb 21 '07 #2

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

Similar topics

18
by: Guinness Mann | last post by:
Greetings, I think I saw an article yesterday in which you told someone not to make an Identity column a primary key. I seem to remember you saying something like "It undermines the entire...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
4
by: Mario Reiley | last post by:
Hi, Group I need transfer a listView.Item's data control to Windows Clipboard for retrive in MS-Excel or another program. Some Idea , some code, may be WEB site which advisor will be...
29
by: MP | last post by:
Greets, context: vb6/ado/.mdb/jet 4.0 (no access)/sql beginning learner, first database, planning stages (I think the underlying question here is whether to normalize or not to normalize this...
0
by: Patrick.O.Ige | last post by:
I have a xml file and i want to format it using XSL I needed to do a distinct which is ok on the first node "Code" But when it gets to the "programDescription" node it prints out values for both...
2
by: raskovsky | last post by:
Hello, I'm new to access, I've used vc++ and sql, but I was required to program this project in access. I have two questions in one. First let me explain my program. It's a huge database which...
9
by: David Eades | last post by:
Hi all Complete newbie here, so apologies if this is the wrong forum. I've been asked to use mysql and asp to make a simple bidding system (rather like a simple ebay), whereby users can use a...
2
by: gdarian216 | last post by:
the object of the project was to create a program that inputs multiple lines of integers and outputs them in an HTML table. The negative numbers should be red. The numbers should be printed 3 in a...
1
Curtis Rutland
by: Curtis Rutland | last post by:
How To Use A Database In Your Program Part II This article is intended to extend Frinny’s excellent article: How to Use a Database in Your Program. Frinny’s article defines the basic concepts...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.