Some Help With C++ Needed.

Fire

CAGiversary!
I needed a quick credit for my degree this semester, so I decided to take a Comp Sci class since I had heard it was easy. So far it isn't too bad, but I'm stuck on this piece of code am unsure of where to go.

create a program that asks for the size of the multiplication table. Your customized border should be resizable based upon the size of the multiplication table.

I've made the program ask for the size of the table, and have a border of * at the top and bottom, but I'm not sure how to make it resizable or how to have * go down on either the left or right side to create the impression of a frame.

Any and all help is much appreciated.
 
I think they mean like the numbers for the dimensions of the table aren't hard coded into your program right?

If that's the case just leave the program in a looping state that keeps taking input until you hit some designated termination number (like -1):

int newDimension = 0;

while( ( cin >> newDimension ) != '-1' )
{
/* Keep rebuilding the table with your stars or whatever */
/* Then ask for the dimension again or something */
}

I'd have to see the assignment to be sure that's what they want... but yeah maybe that helps.
 
[quote name='MadChedar0']I think they mean like the numbers for the dimensions of the table aren't hard coded into your program right?

If that's the case just leave the program in a looping state that keeps taking input until you hit some designated termination number (like -1):

int newDimension = 0;

while( ( cin >> newDimension ) != '-1' )
{
/* Keep rebuilding the table with your stars or whatever */
/* Then ask for the dimension again or something */
}

I'd have to see the assignment to be sure that's what they want... but yeah maybe that helps.[/QUOTE]

Well, I could show you what I have built, but I'm not sure how to copy and paste of PuTTY. Yes I know, my school is extremely cheap.
 
Actually, here it is:

int main ()
{
int x, y, NumColumn, NumRow;


printf ("What is the height you would like your multiplication table to be?""\n");
scanf ("%d", &NumColumn);

printf ("What is the width you would like your multiplication table to be?""\n");
scanf ("%d", &NumRow);


//Prints out first border row of *

for(x=1;x
 
Putty opens up as a regular screen terminal, you should be able to click something like "Edit-->Select All" which will select everything in the terminal up to a point.... but then you can select one contiguous block of text with your cursor. Once that's selected you can Ctrl-C and copy the text you selected.

Then paste wherever.

Hopefully that made sense.

Edit: So what screws up exactly?
 
[quote name='MadChedar0']Putty opens up as a regular screen terminal, you should be able to click something like "Edit-->Select All" which will select everything in the terminal up to a point.... but then you can select one contiguous block of text with your cursor. Once that's selected you can Ctrl-C and copy the text you selected.

Then paste wherever.

Hopefully that made sense.[/QUOTE]

shoot your right. I could have just copied to the clipboard. Totally overlooked that part. Still, putty stinks compared to working with Microsoft VC.
 
[quote name='MadChedar0']

Edit: So what screws up exactly?[/QUOTE]

I need to create a border of my choosing that goes around the entire table and stretch or shorten depending on the inputs given.

I can get a top frame, but then i can't get it to expand or decrease and I can't get it to go all the way around.
 
So while you're building each row, print one border character, then tab, print the board, then print the other border character.

So like

//Prints out multiplication table

printf(" "); // place your character in here too plus another space
for(y=1;y
 
[quote name='MadChedar0']So while you're building each row, print one border character, then tab, print the board, then print the other border character.

So like

//Prints out multiplication table

printf(" "); // place your character in here too plus another space
for(y=1;y
 
Don't forget your ';', those things drove me nuts after pages and pages worth of codes and getting compiling errors. Damn you ';'!!!!!!!!!!!!1
 
[quote name='SteveMcQ']Don't forget your ';', those things drove me nuts after pages and pages worth of codes and getting compiling errors. Damn you ';'!!!!!!!!!!!!1[/quote]

LoL - computer lab fun, replace multiple random ; with : when your buddy takes a break.
 
As for putting together your top and bottom rows, it depends on a few things. The number of asteriks should be something like ...

//begin pseudocode

MaxDigits = Maximum number of digits used in the column (for example, on a 10 x 10 table, with the highest factor being 10, the largest number of digits would be 3. i.e., 10 x 10 = 100, 100 has three digits).

NumSpaces = The number of spaces you've allocated between each column.

NumAsteriks = NumColumns * ( NumSpaces + MaxDigits )

for(int i = 0; i < NumAsteriks; i++)
printf("*");

Use NumAsteriks as your loop control variable and you should be relatively close (you'll need to adjust for a little bit more because this will still be short by a few asteriks, based on your left and right side borders).

I think that might work, but I don't have a compiler handy so I can't be 100% on it.
 
[quote name='the_gloaming']As for putting together your top and bottom rows, it depends on a few things. The number of asteriks should be something like ...

//begin pseudocode

MaxDigits = Maximum number of digits used in the column (for example, on a 10 x 10 table, with the highest factor being 10, the largest number of digits would be 3. i.e., 10 x 10 = 100, 100 has three digits).

NumSpaces = The number of spaces you've allocated between each column.

NumAsteriks = NumColumns * ( NumSpaces + MaxDigits )

for(int i = 0; i < NumAsteriks; i++)
printf("*");

Use NumAsteriks as your loop control variable and you should be relatively close (you'll need to adjust for a little bit more because this will still be short by a few asteriks, based on your left and right side borders).

I think that might work, but I don't have a compiler handy so I can't be 100% on it.[/QUOTE]

I tried that just now and it gave me hardly any * at the top columns. Thanks for the help though.
 
[quote name='Quillion']This should work, just from glancing at it. I'd be a little concerned at the order of operations in "x
 
I quoted my old segment, but just add in the other "*" to get it to appear on every line.

[quote name='the_gloaming']It's been a while since I used C++, but ...

In this code segment:

for(x=1;x
 
[quote name='camoor']LoL - computer lab fun, replace multiple random ; with : when your buddy takes a break.[/QUOTE]

At first I found that really funny, but it's kind of spoiled by the fact that when you go to compile your editor is going to say, "Syntax error: line X" or whatever. Now if it didn't give you a line number... :)
 
bread's done
Back
Top