1000 random numbers and this play the percentage of odd

#include <iostream>
#include <ctime>
using namespace std;
int main ()
{
int i,j;
srand ( (unsigned)time( NULL ) );
//Display 10 random numbers
for ( i = 0;i < 10;i++)
{
j= rand() %1000;
cout << j << endl;
}
system ("pause");
return 0;
}
///////This is my code but can't get the percentage of the odd ones///////////
Eloborate on "can't". Don't you know how to tell whether a number is odd or what?
Is your question "How can I calculate the percentage of odd numbers I get in a thousand random integers?"
It is obvious that you should count total of numbers and how many among then there are odd ones. As total is known (it is equal to 10 ) then you need count only odd ones.
For example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;

int main ()
{
   int count = 0;
   std::srand ( std:;time( NULL ) );

//Display 10 random numbers
   for ( int i = 0; i < 10; i++ )
   {
      int value= rand() % 1000;
      cout << value << endl;
      if ( value % 2 != 0 ) count++;
   }

   cout << "persentage of the odd ones = " << count * 10 /* ( count / 10 ) * 100% */ 
           << std:;endl;           
   system ("pause");

   return 0;
} 
Last edited on
ya tryed that code but it stil won't complie it has errors on line 10 and 21,do i need another curly bracket on them lines
No, you need to write your own code.
i did write what i knew but im stuck now ok
then how about answering the questions ok
ya tryed that code but it stil won't complie it has errors on line 10 and 21,do i need another curly bracket on them lines


If you can't spot the errors in those lines, this task is beyond you and you should go back to the beginning.
im still trying to get it working but not having any luck
luck won't help you much with programming that's why you need to start with learning the basics like you were told ok
I think you should check that everywhere in the code there is :: and not :; or ;; or :;
Or remove everywhere the namespace prefix std:: because there is already directive using namespace std;
Last edited on
Topic archived. No new replies allowed.