vendredi 29 décembre 2017

Sum of random numbers from a string character count

So I have been working on this problem for a few days now. I have tried several things and done a lot of searching, but I just can't figure this one out. So my question is does anyone have an idea of a way to add the 5 random numbers together and print the sum? I was trying to assign them to an array, so far no luck. Any help would be greatly appreciated.

    #include <iostream>  
    #include <string>  
    #include <cstdlib>  
    #include <ctime>
    int main()
    {
    std::string str;  
    std::getline(std::cin, str);  
    int y = str.size();  
    std::srand(time(0));  
    for (int x = 1; x <= 5; x++)  
    {     
        std::cout<<1 + (std::rand() % y)<<std::endl;  
    }  
    return 0;  
    }  




Aucun commentaire:

Enregistrer un commentaire