Jump to content
IGNORED

C++ help


Iron Chef Pontiff

Recommended Posts

Well Im in need of some help.  For some reason Im not able to get this program to run for class.  Ill post the code and maybe someone can give me a clue as to what Im missing.  The purpose of the program is in the menu.  Sorry no notes.

 

http://www.playnintendo.com/boards/phpBB2/...p?p=10588#10588

 

Array indexing starts at 0, not 1, and goes to the array dimension -1

 

So, declaring an array like this...

 

int array[4];

 

and using it like this...

 

array[4] = 0;

 

 

Will cause your program to crash. The last element of the array is array[3], and the first element is array[0]. You seem to be accessing the last element as array[4] in several places in your code, so that's one thing to fix.

 

Cheers

A

Link to comment
Share on other sites

I changed that.  I get my menu and prompt to enter a selection but after I enter the selection I dont get the prompt to enter the number of rows.  I think I have all of my cout statements correct.  Is it maybe a problem with the switch or while statement?

 

This is happening because you input selection as a character, so when you press the key 1, the character '1' is stored in the variable. This is definitely not the same as the VALUE 1. From memory, character 1 has value 49 in ASCII. Change your switch statement to

 

case '1':

 

and elsewhere where you do that sort of checking.

 

Cheers

A

 

 

PS: You're aware I'm $150 an hour?

Link to comment
Share on other sites

That did it.  Boy do I feel dumb.  Thanks for the help.  How would you like me to pay?  Remember Im a poor starving college student.

 

Respect your elders, help those in need when you can, and one day when you're an expert in your field remember that once you, too, were a newbie needing help.

 

Cheers

A

Link to comment
Share on other sites

Array indexing starts at 0, not 1, and goes to the array dimension -1

Although this is true for C and C++, some languages use array indicies of 1 to n. Trying to write to (and sometime read from) array elements outside of these bounds can cause problems. (Trust me, I one had a bug in a program which wrote to array[-1]. It took a long time to figure it out because the program didn't crash until it exitted.)

 

We havent even looked at the libraries yet.

Ahh, but you have. stdlib is a C library with a bunch of functions. cin & cout are part of the C++ iostream library.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...