oooooooooookay ladies and gentlemen,
let me just get this out there this is like my 3rd or 4th week since actually starting to learn C++, I've been following along with a book for a while but decided to let go of the book for a bit and try my hand at making (what I thought to be) a basic 'program'.
Anyway, the 'program' I wanted to build simply generated a table with random people, age, gender. I just wanted to see if I could do it (obviously that's not the case so shh) I still wanted to get it done so I looked on the internet but to no avail the few people that tried to help didn't.
So this is what I have so far and it is far from displaying 'random' data, its basically randomises an integer for age and then makes that age constant through the entire program (I want every different character to be random)
[CODE]#include "std_lib_facilities.h"
#include<iostream>
#include<conio.h>
using namespace std;
void main()
{
const string firstname[][25] = {
"William","Jack","Joshua","Lachlan","Thomas","Cooper","James","Oliver","Riley" ,"Ethan",
"Benjamin","Noah","Daniel","Samuel","Liam","Alexander","Ryan","Max","Lucas","Matthew","Jacob", //list of random names I pulled off some website
"Charlie","Jayden","Luke","Nicholas"
};
int age;
int i = 1;
int first_name = 1;
int last_name = 1;
string sex;
int sexi;
srand ((long)time(NULL));
age = rand() % 99 + 8;
srand ((long)time(NULL));
first_name = rand() % 10 + 1;
srand ((long)time(NULL));
last_name = rand() % 25 + 1; //Like I said, this is my 4th week or so programming and
//and I still don't understand how srand functions work
srand ((long)time(NULL));
sexi = rand() % 2 + 1;
if(sexi = 1)
sex = "Male";
else sex = "Female";
cout<<"Press Enter to Generate"; //Only want to list 25 people
cin.get();
while(i<25)
{
cout<<"#"<<'\t'<<"Name"<<'\t'<<"Age"<<'\t'<<"Sex"<<'\n'; //Just like the top of any table, shows what will be in the columns
cout<<i++<<'\t'<<"John"<<'\t'<<age<<'\t'<<sex<<'\n';
keep_window_open();
}
}
[/CODE]
Now I realise I am way out of my knowledge here and I promise after this I'll go back to reading the book, but I NEED TO GET THIS DONE MAAN.
Cheers
[cpp]
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
const string firstname[25] = {
"William","Jack","Joshua","Lachlan","Thomas","Cooper","James","Oliver","Riley" ,"Ethan",
"Benjamin","Noah","Daniel","Samuel","Liam","Alexander","Ryan","Max","Lucas","Matthew","Jacob", //list of random names I pulled off some website
"Charlie","Jayden","Luke","Nicholas" };
int age;
int i = 1;
int first_name = 1;
int last_name = 1;
string sex;
int sexi;
srand (time(NULL)); //only need one of these random seeds
while(i<25)
{
age = rand() % 99 + 8;
first_name = rand() % 10 + 1;
last_name = rand() % 25 + 1;
sexi = rand() % 2;
if(sexi) { sex = "Male"; }
else { sex = "Female"; }
cout<<"#"<<'\t'<<"Name"<<'\t'<<"Age"<<'\t'<<"Sex"<<'\n'; //Just like the top of any table, shows what will be in the columns
cout<<i++<<'\t'<< firstname[first_name] <<'\t'<<age<<'\t'<<sex<<'\n';
}
cin.get();
return 0;
}
[/cpp]
Here you go. It needs some tweaking on your side but I don't want to spoil all of your fun. It works now.
Thanks a lot man
Sorry, you need to Log In to post a reply to this thread.