-
help!!
i have created this code but now i have to create a user defined function and everything i do it comes out wrong help!!!
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include<cstring>
#include <iomanip>
using namespace std;
int main(int argc, char* argv[]){
const char* article[5]={"the", "a", "one", "some", "any"};
const char* noun[5]={"boy", "girl", "dog", "town", "car"};
const char* verb[5]={"drove", "jumped", "ran", "walked", "skipped"};
const char* preposition[5]={"to", "from", "over", "under", "on"};
cout<<*(article+(rand()%5));
cout<<" ";
cout<<*(noun+(rand()%5));
cout<<" ";
cout<<*(verb+(rand()%5));
cout<<" ";
cout<<*(preposition+(rand()%5));
cout<<" ";
cout<<*(article+(rand()%5));
cout<<" ";
cout<<*(noun+(rand()%5));
cout<<".\n";
return 0;
}
-
here's what i tried it sort of works but it doesnt randomly pick it always gives
a dog skipped to any car.
help?
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include<cstring>
#include <iomanip>
using namespace std;
void sent( const char *article[], const char *noun[], const char *verb[], const char *preposition[],int size){
cout<<*(article+(rand()%5))<<flush;
cout<<" "<<flush;
cout<<*(noun+(rand()%5))<<flush;
cout<<" "<<flush;
cout<<*(verb+(rand()%5))<<flush;
cout<<" "<<flush;
cout<<*(preposition+(rand()%5))<<flush;
cout<<" "<<flush;
cout<<*(article+(rand()%5))<<flush;
cout<<" "<<flush;
cout<<*(noun+(rand()%5))<<flush;
cout<<".\n"<<flush;}
int main(){
const int size=5;
const char *article[size]={"the", "a", "one", "some", "any"};
const char *noun[size]={"boy", "girl", "dog", "town", "car"};
const char *verb[size]={"drove", "jumped", "ran", "walked", "skipped"};
const char *preposition[size]={"to", "from", "over", "under", "on"};
sent(article, noun, verb, preposition,size);
return 0;
}
-
Code:
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
const char* article[5]={"the", "a", "one", "some", "any"};
const char* noun[5]={"boy", "girl", "dog", "town", "car"};
const char* verb[5]={"drove", "jumped", "ran", "walked", "skipped"};
const char* preposition[5]={"to", "from", "over", "under", "on"};
srand((unsigned)time(NULL));
cout<<*(article+(rand()%5));
cout<<" ";
cout<<*(noun+(rand()%5));
cout<<" ";
cout<<*(verb+(rand()%5));
cout<<" ";
cout<<*(preposition+(rand()%5));
cout<<" ";
cout<<*(article+(rand()%5));
cout<<" ";
cout<<*(noun+(rand()%5));
cout<<"."<<endl;
return 0;
}
-
that's all good but i need a user defined funct not one from a library
-
A user-defined function to do what?
-
i have to put part of the program in a function
but as u can see from what i tried it almost worked but has a few bugs i have that part as the first reply
-
Code:
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
void loop();
int main()
{
loop();
return 0;
}
void loop()
{
const char* article[5]={"the", "a", "one", "some", "any"};
const char* noun[5]={"boy", "girl", "dog", "town", "car"};
const char* verb[5]={"drove", "jumped", "ran", "walked", "skipped"};
const char* preposition[5]={"to", "from", "over", "under", "on"};
srand((unsigned)time(NULL));
cout<<*(article+(rand()%5));
cout<<" ";
cout<<*(noun+(rand()%5));
cout<<" ";
cout<<*(verb+(rand()%5));
cout<<" ";
cout<<*(preposition+(rand()%5));
cout<<" ";
cout<<*(article+(rand()%5));
cout<<" ";
cout<<*(noun+(rand()%5));
cout<<"."<<endl;
}
lol
-
thanx good enough my man
:cool: :cool: