I need to write code to:
1. receive user input
2. output to an html table - 3 columns user integer input, 4th column sum of the three
3. if the integer is negative, it needs to print out red
4. if the user enters a zero, I need the row in play to blank out, all the columns to be totalled, and the program to end
I have been working on this for quite some time. My table is fine, the first row is correct - after that things go bad. I would really appreciate any help. Many thanks!
#include <iostream>
using namespace std;
int main()
{
//declare variables
int number = 0;
int num1 = 0, num2 = 0, num3 = 0;
int num1_total = 0, num2_total = 0, num3_total = 0;
int num_sum = num1 + num2 + num3;
int sum_total = 0;
int num_count = 0;
bool end_sum = false;
bool end_row = false;
"table.cpp" 123L, 3592C 1,1 Top
// Construct an integer table
int num_count = 0;
{
end_sum = true;
end_row = true;
switch (num_count) //if the input equals zero, all equal zero, print table
{
case 1: num1 = 0;
break;
case 2: num2 = 0;
break;
}
if (number != 0) //if the input is not zero read 3 inputs into the table row
{
cout << "<tr>" << endl;
cout << "<td>" << num1 << "</td> <td>" << num2 << "</td> <td>" << num3 << "</td> <td>" << "</td> <td>" << num_sum << "</td> <td>" << endl;
cout << "</tr>" << endl;
if (number < 0) //if input is less then zero print with red font
{
cout << "<tr>" << endl;
cout << "<td><font color=FF0000>" << num1 << "</td>" << num2 << "</td>" << num3 << "</font></td>" "<td>" << num_sum << "</td> <td>" << endl;
cout << "</tr>" << endl;
}
}
}
else // not the end of the row
{
num_count++;
switch (num_count) //assign three input values to variable names
{
case 1: num1 = number;
num1_total += num1;
break;
case 2: num2 = number;
num2_total += num2;
break;
case 3: num3 = number;
num3_total += num3;
break;
case 4: num_sum = num1 + num2 + num3;
break;
case 5: sum_total += num_sum;
end_row = true;
break;
default: end_row = true;
break;
}
}
}
else //end of input print table
{
cout << "<tr>" << endl;
cout << "<td>" << num1 << "</td><td>" << num2 << "</td><td>" << num3 << "</td><td>" << num_sum << "</td><td>" << endl;
cout << "</tr>" << endl;
cout << "<tr>" << num1_total << "</td><td>" << num2_total << "</td><td>" << num3_total << "</td><td>" << sum_total << "</td><td>" << endl;
end_row = false;
num_count = 0; }
//end of user input
}
cout << "</table>" << endl;
cout << "You may view the table now.";
return 0;
}