c1.doit();
c1.writeit();
getch();
c2.sayit(40); <----- Number of random numbers to be this.
c2.doit();
c2.writeit();
I'm trying to get the random numbers to output different sizes. I'm not really sure how to do it so if you could look at it and see what I'm doing wrong. I know in a regular function you would just put the number in there, so any help is great.
I get the feeling that you are using code tags wrong because you have code in the output panel. http://www.cplusplus.com/articles/firedraco1/ (But at least you used them, although that code should still be indented.)
Anyway, I don't see how you can double-define sayit (int). That really shouldn't work. In addition, there's a lot of stuff you have calls to that you don't show us. What are random() and randomize()?
And lastly, I really don't understand what your objective is. What is it you have in mind?
sorry, i tried fixing the code, for some reason they keep showing on the output.
randomize is for making the numbers random every time i run the program. random(999) is to get at most a 3 integer number.
I am trying to make the program output random numbers. I want to make it so that I can put the size of the array in the c1.sayit() and then it runs for that number you put in there.
so for example
c1.sayit(20)
getch();
c1sayit(40)
after I would output it I want to see that the size has actually changed.
also I was trying random things to make it work so if you see something wrong there is a high possibility it is.
What you have posted still won't compile because it isn't complete. How do you expect anyone to help you when you won't even show us what the problem is?
I think you believe that, when you say sayit (int size), the member size is going to get changed to a certain value. It won't. The variable size in sayit is at function scope - it is an argument of sayit, not a member of class1 - and it doesn't in any way affect the member size of the calling class. That's what the compiler is warning you about. When you try to access size, you get an undefined result that leads to this crash, potentially.
And where do you define sayit()?
Well that should work. But when you do this: sayit(int size)
That SIZE in the argument list is a completely separate thing from Class1::size. You get the argument size in the function, but that does absolutely NOTHING to the size member stored in your class object. You have no assignment in the function and so it changes NOTHING. Change that name to something else and do this:
1 2 3 4 5
void changingamember(int value) // even if this is the same name as someclassmember,
// it does not affect someclassmember EVER unless you perform an assignment in the function
{
someclassmember = value;
}