| | |
problem printing output
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Mar 2005
Posts: 25
Reputation:
Solved Threads: 0
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
why is the output showing only the last column of the table??
puzzeled,
arjun
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
C++ Syntax (Toggle Plain Text)
#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
You may want to make your tables -- and dummy input --have int type. A character 0 ('\0') is not the same as '0'. Either that, or use '0' and '1' in the char table.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Mar 2005
Posts: 25
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
You may want to make your tables -- and dummy input --have int type. A character 0 ('\0') is not the same as '0'.
•
•
•
•
Either that, or use '0' and '1' in the char table.
Last edited by Dave Sinkula; Mar 10th, 2005 at 1:38 pm. Reason: fixed QUOTE tag
•
•
•
•
Originally Posted by arikeri
This isn't helping me either . The function ain't compiling??
#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(){
}/* my output
Enter 1)The number of inputs
2)Number of states ,and
3)Number of outputs
of the sequential state machine
1 0 1
101
please write out the chrecteristic table of your flip-flop on a piece of paper
Iam assuming FF with 2 inputs and 2 states
The first two columns have been filled by the program in the order corresponding to q=0,q=1,q=2 and q=3
Enter the third column of the CHARECTERISTIC table
Enter M for the memory state and T for toggle state
The order in which you enter the values is important
1 0 1 1
0 0 1
0 1 0
1 0 1
1 1 1count = 12
00110101
*/ "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Mar 2005
Posts: 25
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Dave Sinkula
I can't see what you're doing. Here's what I had done.
A sample run is then as follows.#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(){ }
/* my output Enter 1)The number of inputs 2)Number of states ,and 3)Number of outputs of the sequential state machine 1 0 1 101 please write out the chrecteristic table of your flip-flop on a piece of paper Iam assuming FF with 2 inputs and 2 states The first two columns have been filled by the program in the order corresponding to q=0,q=1,q=2 and q=3 Enter the third column of the CHARECTERISTIC table Enter M for the memory state and T for toggle state The order in which you enter the values is important 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 1count = 12 00110101 */
my apologies,
I actually put double qoutes viz;"0"
Thanks a lot for the reply
Arjun
•
•
Join Date: Mar 2005
Posts: 25
Reputation:
Solved Threads: 0
Hi,
I have one more problem now. For the same assignment I need to generate a table of the following king
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.
I have one more problem now. For the same assignment I need to generate a table of the following king
C++ Syntax (Toggle Plain Text)
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.
Last edited by Dave Sinkula; Mar 10th, 2005 at 4:26 pm. Reason: Used code tags to preserve spacing.
I'm still somewhat fuzzy on what it is you're doing, but then I've got a bit of a cold right now.
Is there anything that you could salvage from the following?
The input/output I tested was as follows.
Is there anything that you could salvage from the following?
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { int r, c, rows, in_c; // // Get input. // cout << "How many input rows? "; cin >> rows; cout << "How many input columns? "; cin >> in_c; int **in = new int*[rows]; for ( r = 0; r < rows; ++r ) { in[r] = new int[in_c]; for ( c = 0; c < in_c; ++c ) { cout << "Enter input[" << r << "][" << c << "]: "; cin >> in[r][c]; } } // // Get output. // int out_c; cout << "How many output columns? "; cin >> out_c; int **out = new int*[rows]; for ( r = 0; r < rows; ++r ) { out[r] = new int[out_c]; for ( c = 0; c < out_c; ++c ) { cout << "Enter output[" << r << "][" << c << "]: "; cin >> out[r][c]; } } // // Do stuff. // for ( r = 0; r < rows; ++r ) { for ( c = 0; c < in_c; ++c ) { cout << in[r][c] << ' '; } cout << " "; for ( c = 0; c < out_c; ++c ) { cout << out[r][c] << ' '; } cout << '\n'; } // // Clean up. // for ( r = 0; r < rows; ++r ) { delete[] in[r]; delete[] out[r]; } delete[] in; delete[] out; return 0; }
C++ Syntax (Toggle Plain Text)
How many input rows? 3 How many input columns? 2 Enter input[0][0]: 1 Enter input[0][1]: 0 Enter input[1][0]: 0 Enter input[1][1]: 1 Enter input[2][0]: 0 Enter input[2][1]: 1 How many output columns? 3 Enter output[0][0]: 1 Enter output[0][1]: 0 Enter output[0][2]: 1 Enter output[1][0]: 0 Enter output[1][1]: 1 Enter output[1][2]: 1 Enter output[2][0]: 1 Enter output[2][1]: 0 Enter output[2][2]: 1 1 0 1 0 1 0 1 0 1 1 0 1 1 0 1
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Problem with printing(showing) output in Java (Java)
- New to Python, help printing output of system calls (Python)
- problem in printing in VB (Visual Basic 4 / 5 / 6)
- printing output file (C++)
- Problem printing from IE6 (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: Clear screen
- Next Thread: Two C++ questions.
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






