Heheh, what fun? It's not like this is an NP complete problem. ;)Quote:
You're spoiling the fun
Printable View
Heheh, what fun? It's not like this is an NP complete problem. ;)Quote:
You're spoiling the fun
Is that right? Hmm . . . *googles it*Quote:
Nope, C++ compilers have to support all of the C headers as well as the C++ version of those headers, but the C headers are deprecated. :)
You're right; if you don't care about namespaces you can use either:
From http://publib.boulder.ibm.com/infoce.../stdcpplib.htmQuote:
The C International Standard specifies 18 headers which must be provided by a conforming hosted implementation. The name of each of these headers is of the form name.h. The C++ Standard Library includes the C Standard Library and, hence, includes these 18 headers. Additionally, for each of the 18 headers specified by the C International Standard, the C++ standard specifies a corresponding header that is functionally equivalent to its C library counterpart, but which locates all of the declarations that it contains within the std namespace. The name of each of these C++ headers is of the form cname, where name is the string that results when the ".h" extension is removed from the name of the equivalent C Standard Library header. For example, the header files <stdlib.h> and <cstdlib> are both provided by the C++ Standard Library and are equivalent in function, with the exception that all declarations in <cstdlib> are located within the std namespace.
Well now, miracles do happen. :) I was talking out my butt based on stuff I'd heard before, but actually being right is a nice change.Quote:
You're right; if you don't care about namespaces you can use eithe
I am still bit confussed someone else on another forum said to do it this way as I am new to c++ and not yet heard or the rand function.
Surley what that is doing is saying i = o if 5 is less than 0 add one so that gonna got like count up 1,2,3,4,5, but what that doing how is that adding up myArray what is 10,20,30,40,50,60,70,80,90,100 ?Code:int myArray[10];
int i;
for ( i = 0; i < 5; i++) // it is offset so 0-9
{
//can add a cout here//
myArray[i] = rand() % 100;
}
Or is i setting up the 10 differnt myArrays then the next bit saying
myArray[i](what will have 9 there = a randomd number modual 100 ?
Edit/Delete Message
rand() produces a pseudo-random number. When you % it with a number, it's putting a limit on how big the number can be. This means you'll receive a number in between 0 and 99 (inclusive).
Your index of i inside the for loop will not fill the array. It will only cycle 5 times. This means that array[0] to array[4] will be filled with random numbers from 0 to 99 while array[5] to array[9] will be filled with any arbitrary values that you cannot guarentee.
so basically what happen is it start at 0 and then increments it each time applying a random number so the loop goes 0 random number, 1 random number, so on so on untill 9 as I want an Array with 10 values
then how would i work out the average once the loop has run throught all 9 and gave each a random value?
Add them up (for example in the same loop) and divide by how many elements your array happens to have.
so if that add a random value to each array how do I then add them and divide by 10?
Create a variable... call it total and set it to 0. Now write a loop that goes through every element of your array and adds it to total and stores the result inside total.
Hint:
Now when you're done with that, divide total by the size of the array, and that will be the average of all numbers inside your array.Code:...
total += array[i];
...
That question has been answered in post #2, #4 and #13.Quote:
Originally Posted by MILLWALLL