mardi 28 février 2017

Convert python function to C++

I made this python code that iterates through a string version of an integer and appends each digit of the integer to a list. I'm learning C++ now and I'm trying to convert the python code to C++. I'm lost however since the syntax is very different. How would you convert this code to C++?

Here is the code in python:

import random

def ranArray():
    mylist=[]
    x = random.randint(100,10000)
    x = str(x)
    for i in x:
        mylist.append(i)
    print(mylist)

ranArray()

I gave it a shot, but wasn't very successful and got stuck trying to replicate the loop:

void ranArray();

int main() {
    ranArray();
    return 0;
}

void ranArray();
    int x;
    x = 100 + (rand() % (int) 10000);
    //x = char x;




Aucun commentaire:

Enregistrer un commentaire