429,365 Members | 3,180 Online
Need help? Post your question and get tips & solutions from a community of 429,365 IT Pros & Developers. It's quick & easy.

adding sums of an html table

 P: 57 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 #include  using namespace std;   int main() {   cout << ""; cout << ""; cout << "";             int value1,value2,value3;                   cout << "
"<< "one"<< ""<< "two" << ""<< "three"<< ""<< "Sum"<< "
"<< value1<<" " << value1 << ""<< value2 << " "<<  value2 << " " << value3 <<"" << value3 << "" << sum << " " << sum << "
" << " " << " " << " " << " " << " " << " " << sum << "
" << sum << "
" << " " << " " << " " << " " << sum << "
" << sum << "
" << " " << " " << sum << "
" << sum << "
";                 cout << "";                 cout << "";                 cout << "" << endl;         int sum;         int count = 1;         while (count > 0) //infinite loop that will only be broken if zero is a input.         {         cin >> value1;                   if(value1 == 0)                 break;                   else                   if (value1 > 0)                 cout << "";                 if (value1 < 0)                 cout << "";           cin >> value2;                 if(value2 == 0)                 break;                   else                   if (value2 > 0)                 cout << "";                 if (value2 < 0)                 cout << "";           cin >> value3;                 if(value3 == 0)                 break;                   else                   if (value3 > 0)                 cout << "";                 if (value3 < 0)                 cout << "";                 sum = value1 + value2 + value3;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cout << "" << endl;                 count ++;     }                 int cell = 1;                 while (cell <=3)                 {                 if (value1 == 0)                 cout << "";                 cout << "";                 cout << "";                 sum = value1;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cell++;                 break;                       if (value2 == 0)                 cout << "";                 cout << "";                 sum = value1;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cell++;                 break;                       if (value3 == 0)                 cout << "";                 sum = value1+value2;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cell++;                   break;                 }   cout << ""; cout << ""; cout << "" << endl;           return 0;   } ps: I know it would have been easier to use functions but the assignment didn't allow it. Feb 21 '07 #1

 P: 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 #include  using namespace std;   int main() {   cout << ""; cout << ""; cout << "";             int value1,value2,value3;                   cout << "
"<< "one"<< ""<< "two" << ""<< "three"<< ""<< "Sum"<< "
"<< value1<<" " << value1 << ""<< value2 << " "<<  value2 << " " << value3 <<"" << value3 << "" << sum << " " << sum << "
" << " " << " " << " " << " " << " " << " " << sum << "
" << sum << "
" << " " << " " << " " << " " << sum << "
" << sum << "
" << " " << " " << sum << "
" << sum << "
";                 cout << "";                 cout << "";                 cout << "" << endl;         int sum;         int count = 1;         while (count > 0) //infinite loop that will only be broken if zero is a input.         {         cin >> value1;                   if(value1 == 0)                 break;                   else                   if (value1 > 0)                 cout << "";                 if (value1 < 0)                 cout << "";           cin >> value2;                 if(value2 == 0)                 break;                   else                   if (value2 > 0)                 cout << "";                 if (value2 < 0)                 cout << "";           cin >> value3;                 if(value3 == 0)                 break;                   else                   if (value3 > 0)                 cout << "";                 if (value3 < 0)                 cout << "";                 sum = value1 + value2 + value3;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cout << "" << endl;                 count ++;     }                 int cell = 1;                 while (cell <=3)                 {                 if (value1 == 0)                 cout << "";                 cout << "";                 cout << "";                 sum = value1;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cell++;                 break;                       if (value2 == 0)                 cout << "";                 cout << "";                 sum = value1;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cell++;                 break;                       if (value3 == 0)                 cout << "";                 sum = value1+value2;                 if (sum > 0)                 cout << "";                 else                 cout << "";                 cell++;                   break;                 }   cout << ""; cout << ""; cout << "" << endl;           return 0;   } ps: I know it would have been easier to use functions but the assignment didn't allow it. Expand|Select|Wrap|Line Numbers #include  using namespace std;   void main()  {       int value[100];         int sum=0;     int count;        cout << endl << "Kindly enter the number of inputs" <> count;       cout << endl << "Kindly enter the values for the specified number of inputs" << endl;     for(int i=0;i> value[i];       cout << endl << endl;     cout << "";     cout << "\n";     cout << "";     cout << "\n\t";     cout << "";             i=0;         while (i < count)     {           if(value[i] == 0)         break;           else               if (value[i] > 0)             cout << endl << "\t\t" << "
value" << i << "" << value[i] << "
value" << i << "" << value[i] << "
Sum " << sum << "
Sum " << sum << "
" << "\n\t\t\t" <<"" << "\n\t\t\t" << "" <<"\n\t\t" <<"";             if (value[i] < 0)             cout << endl << "\t\t" << "" << "\n\t\t\t" <<"" << "\n\t\t\t" <<"" <<"\n\t\t" <<"";           sum = sum + value[i];         i++;     }         if (sum > 0)     cout << endl << "\t\t" << "" << "\n\t\t\t" <<"" <<"\n\t\t\t"  <<"" <<"\n\t\t" <<"";     else     cout << endl << "\t\t" << "" << "\n\t\t\t" <<"" <<"\n\t\t\t"  <<"" <<"\n\t\t" <<"";         cout << "\n\t";     cout << "" << endl;     cout << "" <" <