GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 06-Mar-2004, 01:01
st8tic1 st8tic1 is offline
New Member
 
Join Date: Mar 2004
Posts: 2
st8tic1 is on a distinguished road
Question

Problem - for loop input


Greetings, I am using Borland CBuilderX (on fedora) and was working on an initial program (newbie, also not finished with the sorting part cause it won't even accept data), but it won't take my input from within my for loop. I was wondering if anyone has any knowledge as to why it won't work? the code looks right to me...
-------------------------------------------------------------------------

CPP / C++ / C Code:
#include <iostream>
int main ()
{
int matrix [2] [2];
  int x=0,z=0,i;

  std::cout<<"This program will sort data into least to most.\n";
 /************************************************************************/
  for (x<2;x=0;x++)
    
for (z<2;z=0;z++)
    {  
std::cin>>i;
      matrix [x][z]=i;
    }
    std::cout<<"input gathered successfully.\n";
/************************************************************************/
  for (x<2;x=0;x++)
    for (z<2;z=0;z++)
      std::cout<<matrix[x][z]<<std::endl;
  for (x<2;x=0;x++)
    for (z<2;z=0;z++)
    std::cout<<matrix [x][z]<<std::endl;
/************************************************************************/
  std::cout<<"Now these numbers will be sorted from least to most.";
  std::cin>>i;
    return 0;
}
Last edited by Garth Farley : 06-Mar-2004 at 09:51. Reason: Please enclose c code in [c] & [/c] for highlighting
  #2  
Old 06-Mar-2004, 07:42
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi st8tic1. (what a strange name!)
It is your for loop constructs. A for loop has three entries in this order:
  1. Initialization (z = 0)
  2. Test (z<2) - The for statement will loop while this is true
  3. Indexing (z++) - This happens at the end of the for statement.

So instead of:
CPP / C++ / C Code:
for (x<2;x=0;x++)

You for loops should look like:
CPP / C++ / C Code:
for(x=0; x < 2; x++)

Hope this helps.
d
 
 

Recent GIDBlogWriting a book by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help on checking user input hihellochao C Programming Language 5 27-Feb-2004 14:30
problem with C code belludandy C Programming Language 1 26-Jan-2004 22:28
a C input question.. tmike C Programming Language 2 19-Sep-2003 03:39
a C input question tmike C Programming Language 1 16-Sep-2003 03:31
Script needed for letting user input a few days of data for tracking and analysis. tradertt MySQL / PHP Forum 3 06-Mar-2003 03:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:27.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.