By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,301 Members | 3,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,301 IT Pros & Developers. It's quick & easy.

can anyone tell me where the infinite loop is and why it won't stop when I input zero

P: 57
I need help with my homework....i have to write a program that inputs multiple lines of integer numbers and outputs them in an HTML table. The numbers should be printed 3 in a row, one number per column. And the last column is the sum. Input should stop when zero is entered. Zero shouldnt be output. Empty cells should be output to complete the table. and the last row should contain the sum of all numbers in each respective column and the total of all the numbers. I have started the code without the HTML tags but i have errors and it isn't working. this is what i have so far..... if anyone can help I would appreciate it. thanks

#include <iostream>
using namespace std;

int main() {
int input;
int InputCount=0;
int RowSize=2;
int ColumId = 0;



while((input <= -1)||(input >= 1));
{
cin>>input;
while (InputCount <= RowSize);
{

if (InputCount == 0);
ColumId =(InputCount % RowSize);
cout << ColumId << endl;
cout << input;
InputCount ++;
cin>>input;
if (input == 0);
cout << "done";

if (InputCount == 1);
ColumId =(InputCount % RowSize);
cout << ColumId << endl;
cout << input;
InputCount ++;
cin>>input;
if (input == 0);
cout << "done";

if (InputCount == 2);
ColumId =(InputCount % RowSize);
cout << ColumId << endl;
cout << input;
InputCount = 0;
cin>>input;
if (input == 0);
cout << "done";

}
}}
Oct 5 '06 #1
Share this Question
Share on Google+
6 Replies


P: 57
#include <iostream>
using namespace std;

int main() {
int input;
int InputCount=0;
int RowSize=2;
int ColumId = 0;



while((input <= -1)||(input >= 1));
{
cin>>input;
while (InputCount <= RowSize);
{

if (InputCount == 0);
ColumId =(InputCount % RowSize);
cout << ColumId << endl;
cout << input;
InputCount ++;
cin>>input;
if (input == 0);
cout << "done";

if (InputCount == 1);
ColumId =(InputCount % RowSize);
cout << ColumId << endl;
cout << input;
InputCount ++;
cin>>input;
if (input == 0);
cout << "done";

if (InputCount == 2);
ColumId =(InputCount % RowSize);
cout << ColumId << endl;
cout << input;
InputCount = 0;
cin>>input;
if (input == 0);
cout << "done";

}
}}
Oct 5 '06 #2

smartway
P: 24
Remove semicolon after while condition
Oct 5 '06 #3

P: 57
Remove semicolon after while condition

thank you I think I was looking at it too long and was missing that. Thanks alot
Oct 5 '06 #4

smartway
P: 24
Is it working fine now?
Oct 5 '06 #5

P: 57
Is it working fine now?
yeah thanks i have to work on the spacing but its good I think Im good now
Oct 5 '06 #6

100+
P: 293
D_C
Edit: Double post, same as here, where it appears the question was already answered.

I have a question, when a 0 is entered, is the sum always going to be blank? If I enter a, -a, and 0 for one row, the sum should be 0. Will 0 or an empty cell be printed? I assume an empty cell since it will be easier.
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.   int input;
  7.   int inputCount=0;
  8.   int rowSize = 4;
  9.   int sum = 0;
  10.  
  11.   do
  12.   {
  13.     cin>>input;
  14.     if(input == 0)
  15.       break; // should break the do while loop
  16.     cout << input << "\t";
  17.     // WriteCell(input)
  18.     sum += input;
  19.     inputCount++;
  20.  
  21.     if(inputCount == (rowSize-1))
  22.     {
  23.       cout << sum << endl;
  24.       // WriteCell(sum);
  25.       sum = 0;
  26.       inputCount = 0;
  27.     }
  28.   } while(true); // while(input != 0) if break doesn't work
  29.  
  30.   // I am assuming always put a blank cell for the last sum value
  31.   while(inputCount++ != rowSize)
  32.   {
  33.     cout << "\t";
  34.     // WriteBlankCell();
  35.   }
  36.   cout << endl;
  37. }
Oct 5 '06 #7

Post your reply

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