vector with 100 ints

Write a program to create a vector of 100 ints. Fill it with 100 small, random
integers between 1 and 100, inclusive, by using an appropriate call from the
math library. Then display the contents of the vector. (Your program should
use rand() and the modulo operator, at least.)..

........................................................................




#include <vector>

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

int main()
{
float f;
vector<string> list(100);
for( int i=0;i<100;i++)
{


f=rand() % 10;

list[i]=f;
}

for(i=0;i<100;i++)
cout<<"your 100random number are"<<endl;


cout<< list[i];
return 0;
}



can someone see what wrong in this code.??thkss
f is not an int. list is not a vector<int>. cout<<list[i] is outside the loop that defines i.
#include <vector>

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

int main()
{
int f;
vector<int> list(100);
for( int i=0;i<100;i++)



f=rand() % 10;

list[i]=f;


for(i=0;i<100;i++)
cout<<"your 100random number are"<<endl;


cout<< list[i];
return 0;
}


this one either is nt working
list[i]=f; is outside the loop that defines i.
cout<<list[i] is outside the loop that defines i.

You need to enclose the sections of code you want the for loops to loop over with curly braces { }
#include <vector>

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

int main()
{
int f;
vector<int> list(100);

for( int i=0;i<100;i++)

{


f=rand() % 10;

list[i]=f;


for(i=0;i<100;i++)
cout<<"your 100random number are"<<endl;


cout<< list[i];
}
return 0;

}

it is stil nt good... it is nt display as it shud though it is compiling
Would you like us to code it for you, or are you going to do some actual work yourself?
I think you need to try a little harder...

You didn't even fix the errors that they mentioned.

You need to brace-enclose the for loop if you want multiple things.
Here is an example:

1
2
3
4
5
6
for(int i = 0; i < 100; ++i)
{
    //do something
    //do something else
    //do something else
}
Also when posting code enclose it in code tags
[code] /*Code goes here*/ [/code]
i have solve it.. in fact the 2nd for loop was nt necessary...
thks guys...
Topic archived. No new replies allowed.