Looping-Proper Iterations and Initializing/Storing Variables

Hi!! This is my first time posting and I'm not sure how much help I'll be able to get here because I can't post my code per my college's plagiarism policy. I am hopeful, though, that someone might be able to at least point me in the right direction with the limited amount of info I can provide.

I'm in a course where all materials are provided (no textbook)-but the information we need isn't always provided to us. I've emailed the professor but have yet to receive a response about this issue-I've also hunted around the internet and the answers I've found include continue, break, goto, or exit statements-or arrays. We aren't allowed to use any of those in this course, except for break in switch statements only.

My code is essentially formatted as follows:

Preprocessor directives

Declaring and initializing variables

cout/cin statements for the user to input one of 3 characters
cout/cin statements for the user to input the number of times they want the loop to run for that particular iteration, up to 5 (it can run again, but they have to put the character in again for it to do that)


switch that associates all variables with the character input by the user

For loop, set to run for each of the characters if they are input. Something like this:

for (StatementX=1, StatementX<=UserInputForNumberOfTimesToRun, StatementX++)
for (StatementY=1, StatementY<=UserInputForNumberOfTimesToRun, StatementY++)
for (StatementZ=1, StatementZ<=UserInputForNumberOfTimesToRun, StatementZ++)

cout/cin statement for input of a dollar amount

Accumulator

cout statement with calculation for average number entered for that stored variable

Option to start loop again if user desires (cout/cin statement)

Final report of averages, total, after all loops have been completed and user has opted to exit the program


Plus all the error checking throughout.


I know this is much more complicated to read than the actual code, so thanks for sticking with me!! My problem is that when I use the cin statement for the number of times the loop should run in a similar format to that above, it cubes it (to be expected.) I've tried other formats, such as:

(StatementX, Statement Y, StatementZ; StatementX<=UserInputForNumberOfTimesToRun, Statement Y<=UserInputForNumberOfTimesToRun, StatementZ<=UserInputForNumberOfTimesToRun; StatementX++, StatementY++, StatementZ++)

When I do that, it no longer stores the values input by the user in the character that I initialized them to.

My code is good and except for this iteration/storage issue-there aren't any other hiccups etc.

I've tried this so, so many different ways so I am really hopeful that someone can help me out. Thank you so much in advance, and thank you for reading my (not really code!)

**Edited to change to "for" loops-initially put them as if, but of course that isn't correct.
Last edited on
There's no such thing as an "if loop".

So you probably want a "for loop".

1
2
3
for (int x=0; x<n; x++)     // note the 2 semicolons separating the 3 statements
    for (int y=0; y<n; y++)
        for (int z=0; z<n; z++)
Last edited on
You're right. It's not clear at all what's going on. No one can help with a specific problem if it can't be described.

You're asking for personal help, but disabled PMs.
Sorry-I've been staring at it for far too long. @tpb, it is a for loop-and in my code it's written properly (not an "if", a "for!") When I tried to implement the fix you suggested, it doesn't loop at all-everything I've seen thus far for "for" loops indicates it should be x>=n, is there something I'm missing to implement it the way you wrote it with only a >?

@kbw, I'm sorry-I just registered for an account and I guess you have to turn on the ability to receive private messages (not automatic.) I have turned it on.

Thanks so much to you both!


Topic archived. No new replies allowed.