Thread: help!!

  1. #1
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45

    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;
    }

  2. #2
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45
    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;
    }
    Last edited by edshaft; 12-17-2001 at 11:47 AM.

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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; 
    }
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45
    that's all good but i need a user defined funct not one from a library

  5. #5
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    A user-defined function to do what?
    zen

  6. #6
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45
    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

  7. #7
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  8. #8
    Registered User edshaft's Avatar
    Join Date
    Nov 2001
    Posts
    45
    thanx good enough my man
    Keep on rollin'!

Popular pages Recent additions subscribe to a feed