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 10-Mar-2005, 06:38
iamsodumb iamsodumb is offline
New Member
 
Join Date: Mar 2005
Location: Mumbai
Posts: 27
iamsodumb is on a distinguished road

problem printing output


Iam reading in a 4row 3column table.
Iam refering to char_function[4][3] in the following code.This is a part of a larger program. You can neglect all other things and look at char_function
my aim is to print it out
CPP / C++ / C Code:
#include<iostream>
using namespace std;
int N, Q, M;//number of user inputs, states, and outputs of the machine
char char_table[4][3] = { {0,0,0},
                          {0,1,0},
                          {1,0,0},
                          {1,1,0} };

char ex_table[4][4] = {   {0,0,0,0},
                          {0,1,0,0},
                          {1,0,0,0},
                          {1,1,0,0} };

void char_func();
void ex_func();
int  power(int n);
//------------------------------------------------------
int main(){
int itr;
    cout<<" Enter  1)The number of inputs\n\t2)Number of states ,and";
    cout<<"\n\t3)Number of outputs \n of the sequential state machine \n";
    cin>> N ;  cin>> Q ;  cin>> M ;
    cout<<N ;  cout<<Q ;  cout<<M ;
    char_func();
    ex_func();
return 1;
}
//int CHARSSM[power(Q)-1][2*(N+M)-1];

void char_func(){
int itr,itr1,itr2;
char dummy;
int count=0;
    cout<<"\n please write out the chrecteristic table of your flip-flop on a piece of paper";
    cout<<"\n Iam assuming FF with 2 inputs and 2 states \n"; //I don't know if can be of different types too.
    cout<<"\n The first two columns have been filled by the program ";
    cout<<"in the order corresponding to q=0,q=1,q=2 and q=3 \n";
    cout<<" Enter the third column of the CHARECTERISTIC table \n";
    cout<<" Enter M for the memory state and T for toggle state\n";
    cout<<" The order in which you enter the values is important\n";

    for(itr = 0; itr < 4; itr++ ){cin>> dummy; char_table[itr][2] = dummy;}

    for(itr1 = 0; itr1 < 4; itr1++ ){cout<<"\n";
       for(itr = 0; itr < 3 ; itr++ ){count++;
           cout<<" "<< char_table[itr1][itr];
       }
    }
    cout<<"count = " << count;
    cout<<"\n\n";
    cout<< char_table[0][0] << char_table[1][0]<< char_table[2][0]<< char_table[3][0];
    cout<< char_table[0][1] << char_table[1][1]<< char_table[2][1]<< char_table[3][1];
}
//----------------------------------------------------------------------------------
void ex_func(){


}

why is the output showing only the last column of the table??

puzzeled,
arjun
  #2  
Old 10-Mar-2005, 07:38
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,648
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by iamsodumb
why is the output showing only the last column of the table??

puzzeled,
arjun

You have an array of char. Output using cout<< assumes an ascii char.

If you want to print the ascii for 0 or 1 using cout<<, you can cast the output variable to an int.

Regards,

Dave
  #3  
Old 10-Mar-2005, 09:09
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Or use an int definition instead of char

Also, your for() loop would be easier to read if you reformatted it to
CPP / C++ / C Code:
for (itr1 = 0; itr1 < 4; itr1++ )
{
    cout << "\n";
    for (itr = 0; itr < 3 ; itr++ )
    {
        count++;
        cout << " " << char_table[itr1][itr];
    }
}
This way spacing and extra lines don't hide code. See this information for formatting suggestions
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #4  
Old 10-Mar-2005, 13:17
iamsodumb iamsodumb is offline
New Member
 
Join Date: Mar 2005
Location: Mumbai
Posts: 27
iamsodumb is on a distinguished road
Hi,
I have one more problem now. For the same assignment I need to generate a table of the following king

a b c.. x1 x1 x3..
0 0 0 0 0 0
0 0 0 0 0 1
0 0 0 0 1 0
.
.
.

0 0 0 1 1 1
0 0 1 0 0 0
0 0 1 0 0 0
.
0 0 1 1 1 1

and so on.

I've shown it for three variables a , b , c (could be more-say k; k is fixed
and three variables x1, x2, x3(could be more-say upto xN.

I am using arrays to store this as both its dimensions are fixed.
The a,b,c need not always go till (1 1 1).Which means that the number of rows for 3 (k)variables a,b,& c may be less than 8 (2^k)


Plz help me out , The submission is in 15 hrs , so its a bit urgent.
  #5  
Old 10-Mar-2005, 13:19
iamsodumb iamsodumb is offline
New Member
 
Join Date: Mar 2005
Location: Mumbai
Posts: 27
iamsodumb is on a distinguished road
formatting ate up all the spaces I had given
I've filled them with underscores

a b c..__ x1 x1 x3..
0 0 0 ____0 _0 _0
0 0 0 ____0 _0_ 1
0 0 0 ____0 _1 _0
.
.
.

0 0 0 ____1_ 1_ 1
0 0 1 ____0_ 0_ 0
0 0 1 ____0_ 0_ 0
.
0 0 1 __1_ 1_ 1

and so on.
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

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
Printing problem Frandy MS Visual C++ / MFC Forum 1 16-Feb-2005 13:47
Apache / PHP problem, maybe output length? HaganeNoKokoro Apache Web Server Forum 2 08-Sep-2004 07:22
using vector or array oshiotse C++ Forum 4 16-Apr-2004 10:59
urgent: problem + output filters jack Apache Web Server Forum 0 04-Feb-2004 22:32
articles -> output Allowee Learning Journal by J de Silva 1 05-Jun-2003 19:47

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

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


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