473,973 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

question on c++ program to make an html table

57 New Member
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 3424
sicarie
4,677 Recognized Expert Moderator Specialist
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
3228
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 foundation of the relational model." I've been thinking about that all night and I think I understand what you're saying, but I have some questions.
35
2761
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 I'm pretty sure the rest of the program is working just fine. The only thing I could think might be wrong is that the if statement can only hold so many values in itself? Let me show what I'm doing: if (table001]>>5]&b&0x1f] != 0 &&
4
4557
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 wellcome. Best Regard Mario
29
3636
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 one data field - but i'm not sure) :-) Background info:
0
1094
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 Code="PRG004" and PRG005 which is CrazyTraining 2 and Program6 I want CrazyTraining 2 for PRG004 and Program6 for PRG005 Any help? Thx
2
311
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 takes the accounting of a construction company. One of the most important things of the program is to load all the bills of the different suppliers. The problem I have is that one bill can be divided for two or more projects with different amounts...
9
3232
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 web browser to view a highest bid and can make a bid. My question is; how can I be sure that when a user submits a bid, that another user isn't also currently submittimg a bid, i.e i can tell user A
2
2094
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 row, one number per column. the fourth column should contain the sum of the numbers in the row (agian if the sum is negative it should be outputed in red). Input should stop when zero is entered, but zero shouldn't be printed if there are any more...
1
27154
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 of using databases very well and is prerequisite reading for this article. Frinny’s article explains how to use a SQL Server in your program, but there are other databases as well. Some of them provide .NET connectors, but for those that don’t,...
0
10347
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
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...
1
11557
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10901
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8452
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
6405
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6542
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4726
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3754
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.