|
-
Apr 26th, 2001, 05:36 AM
#1
Thread Starter
Lively Member
chars and couts, easy kinda question.
Hi all,
I was wondering if anybody has any idea why my simple 'V' Graphic drawing program isn't work, it appears to be working but isn't diaplaying the v sybol on the screen. The way it works is you type in a smybol and it makes a v using that symbol/char. Quite simple but i can't get it to display properly, below is the code i made in vis c++...
#include <iostream.h>
//declare variables
char sim;
char vee [10] [20] = { {sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', sim , ' '},
{' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim, ' ' , ' '},
{' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ', ' ' , 'V'},
{'V' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ', ' ' , 'V'},
{'V' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ', ' ' , 'V'},
{'V' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ', ' ' , 'V'},
{'V' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , 'V'},
{'V' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , 'V'},
{'V' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , 'V'},
{'V' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , 'V'}};
int col;
int row;
int main()
{
cout << "****** Welcome to the V Drawing Program!! ********\n" << endl;
cout << " Program By Ben Smith\n" << endl;
cout << "Please enter any symbol to create the graphic V: ";
cin >> sim;
for( row = 0; row = 10; row++)
{
for( col = 0; col = 20; col++)
{
cout << vee [row] [col];
}
}
return 0;
}
Any response will be greatly appreciated!!
Thanks
Regards,
Smithy.
-
Apr 26th, 2001, 06:37 AM
#2
Thread Starter
Lively Member
Quick additional note
Where the 'V''s are they are really supposed to be ' ' spaces
-
Apr 26th, 2001, 07:09 AM
#3
Thread Starter
Lively Member
Updated version of my code
I've been working on it for the past 30 mins, here's an updated version of my code...
#include <iostream.h>
//declare variables
char sim;
char vee [10] [20] = { {sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', sim , ' '},
{' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim, ' ' , ' '},
{' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '}};
int col;
int row;
int main()
{
cout << "****** Welcome to the V Drawing Program!! ********\n" << endl;
cout << " Program By Ben Smith\n" << endl;
cout << "Please enter any symbol to create the graphic V: ";
cin >> sim;
for( int row = 0; row == 10; row++)
{
for( int col = 0; col == 20; col++)
{
cout << vee [row] [col];
}
cout << endl;
}
cin >> sim;
return 0;
}
-
Apr 26th, 2001, 07:27 AM
#4
Frenzied Member
Seems like you've misunderstood how procedural programming works a bit.
Your declaration of the array with contents like that isn't going to work I'm afraid, that would be too easy You have to manually assign values to the elements you want after you have got your input. So you could use some code like this:
Code:
#include <iostream> // standard iostream header
using namespace std; // need this to simplify access to standard
// functions when using standard header
char sim;
char vee[10][20];
int col, row;
int main()
{
cout << "****** Welcome to the V Drawing Program!! ********\n" << endl;
cout << " Program By Ben Smith\n" << endl;
cout << "Please enter any symbol to create the graphic V: ";
cin >> sim;
// fill the 'vee' with spaces
for(row=0; row<10; row++)
for(col=0; col<20; col++)
vee[row][col] = ' ';
// change the elements that are part of the vee to the character sim
int begin, end;
row = 0;
for(begin=0, end=19; begin<10; begin++, end--)
{
vee[row][begin] = sim;
vee[row][end] = sim;
row++;
}
// now print out the array
for(row=0; row<10; row++)
{
for(col=0; col<20; col++)
cout << vee[row][col];
cout << endl; // need to print a newline after each row
}
return 0;
}
Harry.
"From one thing, know ten thousand things."
-
Apr 26th, 2001, 07:27 AM
#5
Thread Starter
Lively Member
Another Code update!
This code outputs the 10 rows but no column spaces and smybols 
#include <iostream.h>
//declare variables
char sim;
char vee [10] [20] = { {sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', sim , ' '},
{' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim, ' ' , ' '},
{' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '}};
int col = 0;
int row = 0;
int main()
{
cout << "****** Welcome to the V Drawing Program!! ********\n" << endl;
cout << " Program By Ben Smith\n" << endl;
cout << "Please enter any symbol to create the graphic V: ";
cin >> sim;
for (int row = 0; row <= 10; row++)
{
for (int col = 0; col <= 20; col++)
{
cout << vee [row] [col];
}
cout << endl;
}
cin >> sim;
return 0;
}
-
Apr 26th, 2001, 07:31 AM
#6
Thread Starter
Lively Member
ok, i think that will do the trick
What can i say i'm too used to programming in vb 
hehehehe
I'll try inputing the sim in after it has been cined and it should be right. I've got the row thing sorted out now, so i'm guessing i just have to create a for statement like yours to add sim to my v graphic?
-
Apr 26th, 2001, 07:42 AM
#7
Frenzied Member

Well yes you will need to use something like a for statement (any kind of loop really) to set up the array with the vee pattern.
I haven't tried the code by the way, so I don't know if it works
Harry.
"From one thing, know ten thousand things."
-
Apr 26th, 2001, 07:48 AM
#8
Thread Starter
Lively Member
Thanks!
Thanks! It's all cool now, i've made the fixes and everything works perfectly, thanks for your help, below is the results which works perfect if your interested. Once again thanks!
#include <iostream.h>
//declare variables
char sim;
char vee [10] [20] = { {sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', sim , ' '},
{' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim, ' ' , ' '},
{' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '},
{' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , sim , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ' , ' ', ' ' , ' '}};
int col = 0;
int row = 0;
int main()
{
cout << "****** Welcome to the V Drawing Program!! ********\n" << endl;
cout << " Program By Ben Smith\n" << endl;
cout << "Please enter any symbol to create the graphic V: ";
cin >> sim;
// fill the 'vee' with spaces
for(row=0; row<10; row++)
for(col=0; col<20; col++)
vee[row][col] = ' ';
//save the vee value
int begin, end;
row = 0;
for(begin=0,end=18; begin<10; begin++, end--)
{
vee[row][begin] = sim;
vee[row][end] = sim;
row++;
}
for (int row = 0; row < 10; row++)
{
for (int col = 0; col < 20; col++)
{
cout << vee [row] [col];
}
cout << endl;
}
cout << "V has been created!" << endl;
cout << "Press any key then [enter] to terminate the program" << endl;
cin >> sim;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|