Can you help?
1.  Write a program that will allow positive integers to perform step sizing in "three" (eg: integer values: 1, 4, 7, 10, 13, and so on)
2.  Need to use two loops in nested form
a. First loop will be a WILD statement that asks for the positive integers and has a way of terminiating itself after step sizing is complete.
b. Second loop is a FOR statement that performs step sizing function and terminates after 10 positive integers have been produced starting with 1 all the time.
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
<yawn> Homework?

BTW: Check your assignement. What is a WILD statement? That's new.. or should it be

#define WILD while

?
0
Commented:
<yawn> Homework?

BTW: Check your assignement. What is a WILD statement? That's new.. or should it be

#define WILD while

?
0
Author Commented:
To: jrk
Sorry, not WILD but WHILE

Outer loop should be a WHILE statement that prompts for and extracts the step size.  Also, terminates the loop after all cases are complete.

Inner loop should be a FOR statement that evaluates and prints the ten number sequence for the step size.

The ForInit, ForExpression and PostExpression parameters control the generation of the proper sequence of numbers.

Two Problems:
1.      I do not know how to account for the number of step sizes without asking the user for the exact number.

2.      My answers comes out starting with the step size and then adds positive integers to 10 instead of starting with the number 1 and adding 10 positive integers.

0
Commented:
the following mishmash is a sort of pseudo code. It shows roughly what you want to do. You should be able to use your knowledge of C to code this up. I sincerely hope that no-one actually posts code for you. If we write your assignment, you will learn nothing; if we do it all through your course, you will get a degree then be thrown out of your first job after a week; none of us want that to happen.

I hope that I am not giving too much away even with this.  Btw, you didn't make the question too clear - is it actually 2 questions? If so, this is the pseudo code for 2) for 1) you just don't prompt for user input & don't need teh outer while loop, if you only want to produce one sequence of numbers, begining with 1 & incrementing by 3.

I hope that this helps - but not too much :-)

int i, value;
<prompt user for integer>
{
value = 1;
for (i =0; i < 10; i++)
{
print value
value = value + <user reply>
}
}
0
Commented:
the following mishmash is a sort of pseudo code. It shows roughly what you want to do. You should be able to use your knowledge of C to code this up. I sincerely hope that no-one actually posts code for you. If we write your assignment, you will learn nothing; if we do it all through your course, you will get a degree then be thrown out of your first job after a week; none of us want that to happen.

I hope that I am not giving too much away even with this.  Btw, you didn't make the question too clear - is it actually 2 questions? If so, this is the pseudo code for 2) for 1) you just don't prompt for user input & don't need teh outer while loop, if you only want to produce one sequence of numbers, begining with 1 & incrementing by 3.

I hope that this helps - but not too much :-)

int i, value;
<prompt user for integer>
{
value = 1;
for (i =0; i < 10; i++)
{
print value
value = value + <user reply>
}
}
0
Commented:
IS THIS WHAT YOU MEAN ?
#include <stdio.h>

int main(int argc, char* argv[])
{
int i, number, step, result;
step = 1;
while (step != 0)
{
printf( "\nEnter a step\n");
result = scanf("%d", &step);

if (step != 0)
for (i =0; i<10; i= i + 1)
{
number = 1 +i*step;
printf("%d, ", number);
}
printf("\n");
}
return 0;
}
0
Commented:
JoJo, why don't you show us what you got so far.
0
Commented:
olgat, since you're new round here, let me take you to one side & have a few words. Please consider this a _gentle_ flaming. It is *not* the start of an argument. It is better to have a few gentle words from me, before some of the other old-timers jump on you :-)

There seems to be only one rule here on EE : WE *DON'T* DO HOMEWORK.

In this forum that means that we don't reply to a question with complete code, especially if it is obviously homework.  Normally we ask what parts the poster is having trouble with, then we give him some descriptive help. It is rarely necessary to actually write code. We also ask the questioner to post any code which he has already written, then we can point out where he is going wrong. We don't just hand him the answer on a plate. In fact, I thought that maybe I had given too much with some pseudo code, rather than by starting by asking what exactly he didn't understand. I was afraid that someone might flame me.

What happens if we just post the code is that the guy isn't forced to think. It would theoretcially be possible to get through college like that. Then he may possibly be chucked out of his first job after the first week - thnk what that would men for his life. Much more likely is that he gets to work with me (it already happened several times). Then management sees a 2 man team & wants 2 men's worth of output. So I do the work of 2, while trying to train him up (and simultaneously look for a new job, in case he isn't trainable).

I hope that this doesn't sound too harsh. Please believe me that it is well meant. May your time at EE be long & your answers many.

With best wishes,

Graham

p.s JoJo, can you try to forget that you saw that code ? <g>
0
Commented:
For Graham
Thank you
0
Commented:
Sorry, I see my comment is an answer. Did not intend to give *that* as an answer. Please reject.
0
Commented:
hey, olgat, don't worry. I'm glad that you took it in the spirit in which it was written. I'm sure that you will be a welcome addition to the community.
0
Author Commented:
KangaRoo, this is what I have so far.  The program runs, but the answer does not start with the number 1.  Instead the answer starts with the StepSize. (eg: if the StepSize entered is 3, the answer should read... 1, 4, 7, 10, 13, 16, 19, 22, 25, 28) Instead, when I enter 3 as the StepSize my answer comes out like this:  3, 4, 7, 10 and so on.  The program should give 10 positive integers starting with 1.  The assignment requires only one pair of "nested" loops.  The outer loop should be a "while" loop, and the inner a "For" statement, where the ForInit, ForExpression and PostExpression parameters control the generation of the proper sequence of numbers.

Sorry I wasn't clearer, first time using this :)

#include <iostream>
#include <string>
using namespace std;

int main ()
{
int CasesProcessed = 0;
int CasesInputted = 1;
cout << "Please enter the number of step size cases; " <<endl;
cin >> CasesInputted;

while  (CasesProcessed < CasesInputted)
{
cout << "Please enter the step size; " << endl;
int StepSize = 0;
cin >> StepSize;

int n = 0;
int i = 1;

for  (i = 1; n < 10; ++n)
{
i += StepSize;
cout << i << endl;
}
++ CasesProcessed;
}
return 0;
}
0
Commented:
your problem is that you are using the variable "i" for two purposes. One to control the loop and one to hold the value which you compute each time round.  Also, you probably want to outoput teh value *before* you add the amount to it.

int n = 0;
int i = 1;

for  (i = 1; n < 10; ++n)
{
i += StepSize;
cout << i << endl;
}

if you use:

int n = 0;   int i;
int total = 1;

for  (i = 1; n < 10; ++n)
{
cout << total << endl;
total += StepSize;
}

I think that you will get what you want.
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
You have the output statements situated wrong. Furthermore it looks neater if you initialize the 'loop couter' in the for statement

i = 1;
//int n = 0;
for  (int n = 0; n < 10; ++n)
{
cout << i << endl;
i += StepSize;
}

Note that the first '3' you mentioned is the one you inputted. It will be clearer if you change

cout << "Please enter the step size; " << endl;

To

cout << "Please enter the step size: ";
0
Commented:
graham_k, why add total? why initialize i in the for and never use it?
0
Commented:
A more compact way to do the inner loop is;

//int i = 1;
//int n = 0;
for (int n = 0, i = 1; n < 10; ++n, i += StepSize) cout << i << endl;
}
0
Commented:
I made a mistake in an earlier comment:
i = 1;
shuld be
int i = 1;
0
Commented:
There is a junk '}' two comments earlier.
0
Author Commented:
graham k and KangaRoo, thank you for all your help and advice!!!
0
Commented:
Hi Kangaroo,

I just came back from a long pub lunch yesterday & have a strict "hands off your own code afetr the pub" rule, So, I thought that I'd browse EE instead. I copied the code & quickly changed the obvious, just to get it running, then gave up.

Sure, if it weren't for this d*mn hangover, I could make it slick & take out unused variables & probably improve it six ways to Friday. But, remember, this is an assignment, and it looks like C++ 101 - it wouldn't do for him to hand in some code that looks like Stroustrup wrote it, would it ? <g>
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.