anyone wanna help me with a little C++ coding?

Walleye

Banned
Dec 1, 2002
7,939
0
0
got an assignment... i just need a little help with how to code:

A: a box making program. you insert the length and height of '#'s, and it makes a hollow box with those dimensions.

B: a counting program. it counts the number of uppercase letters, lower case letters, digits, and punctuation and special characters in an entered set.

i'm confused as hell with how to do this. i barely know a simple calculator...
 

brtspears2

Diamond Member
Nov 16, 2000
8,659
1
81
A. Nested For loop.
B. Crap, I knew how to do this... getchar, convert to ascii value, if uppercase, incrememnt that counter, and so on...

<-- hasn't coded for ... years.

Now formatting the box might be a slight challege, just work it out on paper. If you got a 2x2 box, and you had to draw it using hash marks, how would you do it? Now break it down into one by one steps in terms the complier knows, like 1+1.

basically ask for the dimensions, draw the top of the box to the specified width...do the sides, remember your width (many ways to do this, even printing out a bunch of spaces), and finally draw bottom. Biggest challenge for a noob here is to keep the for loop neat and not to get lost in it.

At least paste what you got, and people will see what they can do to help you out, short of giving it away.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Sounds like you've moved on to loops -- learn this well, you'll write thousands of them if you ever do real programming.

Aside from commands, you're supposed to be learning to think your way through problems -- if you get a working sample from someone else without at leasing coming up with a working idea of how to do the assignments you'll be cheating yourself of some important training you'll need even more later.

Can you figure out anything about the proper approach to these problems?
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: DaveSimmons
Sounds like you've moved on to loops -- learn this well, you'll write thousands of them if you ever do real programming.

Aside from commands, you're supposed to be learning to think your way through problems -- if you get a working sample from someone else without at leasing coming up with a working idea of how to do the assignments you'll be cheating yourself of some important training you'll need even more later.

Can you figure out anything about the proper approach to these problems?

i'm thinking for the box, you just do a cin for each variable, and tell it to cout (variable) for the count. keep repeating that loop till it finishes, then end the line.


i dont know how to give it an infinant possibility...i wouldnt know how to end it either...
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
For the box,

#####
# #
#####

you're off to a good start but you need to think about how to cout
(a) the top of the box
(b) the middle of the box
(c) the bottom of the box (which in this case is just like (a))

You might start off by trying to wirte code to create (a) for a given w and h (you can ignore h for now), then tackle (b), then think about the outer loop that uses the code for (a) and (b).

 

Walleye

Banned
Dec 1, 2002
7,939
0
0
wait a second, i see this... you tell it to run the loop that creates the middle lines the height entered variable - 2..


how do i use the for loop for this, though?
 

imported_vr6

Platinum Member
Jul 6, 2001
2,740
0
0
for the counting alphabet part. It'll be a for loop with a extra counter variable to count the number of upper/lower case along with some string.h methods...hope that helps.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: Walleye
wait a second, i see this... you tell it to run the loop that creates the middle lines the height entered variable - 2..


how do i use the for loop for this, though?
for (i = 1 ; i = (h-2) ; i ++ )
{
. . .code here to write 1 "hollow" box row . . .
}

 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: Walleye
wait a second, i see this... you tell it to run the loop that creates the middle lines the height entered variable - 2..


how do i use the for loop for this, though?

Yes, that would be correct. Do you know how to use any of the looping constructs in C++ (while, for, do/while)? Here's an example:

for (int i = 0; i < HEIGHT - 2; i++) // ...

You also need to account for the number of spaces in the non-boundary lines. The number of spaces would be the length - 2:

for (int i = 0; i < LENGTH - 2; i++) // ...

That should get you started. Post code showing your progress...
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
#include <iostream>

using namespace std;
int main(void)
{
int x = 0;
int y = 0;
int blank = x - 2;
int blankl = y - 2;

if (;;)
{

cout << &quot;Please enter a width&quot; << endl;
cin >> x ;

cout << &quot;Please enter a height&quot; << endl;
cin >> y ;

for ( x = 0; x ++)
{



that's as far as i am right now...


pretty basic, i'm just stumped.. :(
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
got it down to 3 errors...


here's my code...


#include <iostream>

using namespace std;
int main(void)
{
int x = 0;
int y = 0;
int blank = x - 2;
int blankl = y - 2;

if (;;)
{

cout << "Please enter a width" << endl;
cin >> x ;

cout << "Please enter a height" << endl;
cin >> y ;

cout << endl;
cout << endl;

for ( x = 0; x ++)
{
cout << "#"
}
cout << endl;

for ( blankl )
{

cout << "#";

for ( blank )
{
cout << " ";
}

cout << "#";
}
cout << endl;
for ( x = 0; x++)
{
cout << "#";
}

cout << endl;
cout << endl;

}

return 0;

}



and here's the compile errors.



line 11 parse error before ; token
line 21 parse error before ) token
line 28 parse error before ) token


i dont understand what's wrong... :(
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
There are many errors in the above code. It's a programmer taboo to write a neophyte's homework. Can you not talk to your teacher? Not to be pejorative, but there are quite a many concepts you've missed, and it's really in your best interest to learn them before trying to go further.
 

xcript

Diamond Member
Apr 3, 2003
8,258
2
81
You've made quite a few horrible mistakes.

If you don't get through them yourself you won't learn anything.
 

Ameesh

Lifer
Apr 3, 2001
23,686
1
0
Originally posted by: xcript
You've made quite a few horrible mistakes.

If you don't get through them yourself you won't learn anything.

i agree, this is about as easy as it gets so if you cant handle it you should really rethink things
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: Ameesh
Originally posted by: xcript
You've made quite a few horrible mistakes.

If you don't get through them yourself you won't learn anything.

i agree, this is about as easy as it gets so if you cant handle it you should really rethink things

listen. i've never taken a programming class before. the most advanced code i know is html. i took this not because i wanted to but because it's necessary for my major.
 

emmpee

Golden Member
Nov 26, 2001
1,100
0
0
Originally posted by: Walleye
Originally posted by: Ameesh
Originally posted by: xcript You've made quite a few horrible mistakes. If you don't get through them yourself you won't learn anything.
i agree, this is about as easy as it gets so if you cant handle it you should really rethink things
listen. i've never taken a programming class before. the most advanced code i know is html. i took this not because i wanted to but because it's necessary for my major.

so that makes it right for us to do your homework? you are missing VERY basic concepts, and us telling you what's wrong won't help you learn. you need to get some tutoring from the teacher or from classmates.
 

Descartes

Lifer
Oct 10, 1999
13,968
2
0
Originally posted by: Walleye
Originally posted by: Ameesh
Originally posted by: xcript
You've made quite a few horrible mistakes.

If you don't get through them yourself you won't learn anything.

i agree, this is about as easy as it gets so if you cant handle it you should really rethink things

listen. i've never taken a programming class before. the most advanced code i know is html. i took this not because i wanted to but because it's necessary for my major.

Surely they went through all this in the class already then? You aren't asking how to handle logic (even as simple as it is), you're asking how to simply looping, conditionals, etc; these are all on page 1 of any discussion of any programming language.
 

Walleye

Banned
Dec 1, 2002
7,939
0
0
Originally posted by: emmpee

so that makes it right for us to do your homework? you are missing VERY basic concepts, and us telling you what's wrong won't help you learn.

i'm asking for help, not people to do it for me.

i am just trying to figure out why my code wont compile. parse errors, i just want to correct those and compile the code. then i'll deal with why it's a sh1tty program.

i know i killed my if statement, i know the 2 x span statements are wrong. i'm trying to figure out why.