C++

Is there anyone on here that can look at my code and tell me what i'm doing wrong?
All I am trying to do is put random numbers into an array then print out the array to the screen.
When I run the code all that prints is '0's..

- no need to seed every iteration
- you're not incrementing 'count' variable

this is why everyone who recommends c++ to beginners should end themselves

Simple, your programming in a dead language. Try switching to the TIOBE highest language: Java

> Codeblocks
> Windows
> Chrome
> Using int
> srand inside the loop
> probably using using namespace std somewhere

You already failed m8

>random[count] >> randomNum
you aren't storing anything in a variable here.
>> for ints is bit shift operator. the expression evaluates and is the equivalent to something like:
>234234;
do
>random[count++] = randomNum
to put randomNum into the array

Thanks for the feedback guys.
I'm rather new to this.
I was able to get it going here is my updated code.

also get rid of the count variable at the top of the method. it's useless. declare it in the final for loop

better yet, just use int i=0 like before

Is there an IDE you recommend?
I've been looking to try something different.

Fuck you and people like your elitist ass. Go back to your arbitrary coding practices.

I realize this now thanks again!

'randomNum' is unused as well lol

wtf we /crypto/ now

I had been trying different methods before posting here so that's why I had totally unused variables lol.
thanks tho I got rid of it.

ideally you should have 1 method to populate or return an array of random ints, and another method to print them. (of any size)

reusable methods and all

t. l33t haxx0r

Is this a part of your home work? If so can you please post the question?

I dont think he was talking about those kinds of methods. Seems like he was using the word in a general sense

k

>srand()ing 5 (FIVE) times
lmao

>meanwhile in python

Not that user, but anything that have what you need, but I personally use LiClipse in windows and just text editor and compiler in linux

How hard is it to keep spacing consistent?

Please for the love of God fix the spacing.

Well damn.

>meanwhile in a gay slow scripting language

Jesus christ wtf are you doing you dumbass winnigger?

>running on an OS written in C/C++

to give you an idea its a lottery program where the user inputs 5 numbers the the the computer prints 5 random numbers then I have to compare the arrays to see if they match.

Wow it's almost like different languages are used for different purposes.

remember to sort the arrays first before comparing them :^)

wow it's like OP is learning C++ and a pythonfag gays up the thread

Yeah that makes sense thanks!

looks to me like he's learning basic programming

10 PRINT"k": GOTO 10

slow speed meme ended with python 3

Thanks everyone that replied, even the not so helpful replies.
As i said before i'm fairly new to all this that being said I'm open to new languages and coding ideas for the sake of educational purposes.
No hate here we are all coders alike!

Something like this?

HOLY FUCK NOBODY SAID HE FORGOT PARENTHESES IN THE SECOND FOR LOOP

hey there. next time try and use a pastebin. it can be difficult to read code in a screenshot. plus we need to retype everything.

I see several issues here.

First it seems like you're using the number 5 to specify that you want to get 4 random integers in an array. That's fine and dandy but it isn't good practice. You want a constant like that to be in variable form. That way if you want to modify the size of your random number array all you do is change the variable. So let's do that.

At the top of the function make an integer variable and call it something self explanatory like array_rand_size. Make it equal whatever you like.

Next move the srand(0) out of the loop. Like another user said, you don't need to constantly provide a seed value. You only do it once.

next it seems like your random array is used in a loop before being declared or even initialized.

So under your array_rand_size you're going to want to declare an array.

int randNums[array_rand_size];

Delete the count variable because you can initialize it within the loop just like you did with the i variable. You want your code to be consistent.

Delete all instances of the randomNum variable. Its not necessary. Think about it. You're getting a random number mod 9 and assigning it to a variable. Its much simpler to do this:

randNum[i] = rand()%9;

You don't use the count variable with the for(int i...) loop. The count variable won't increase. In other words you have the right idea but you're using the wrong variable. All you're doing is reassigning the value of the first item in the array.

Next let's change i

more like an indentation error

Stop doing the homework for the guy.

Let the guy figure it out for himself, then have him ask questions.

Nah nigga I'm pretty sure he wanted to print the endline after printing all the numbers. It's just that his spacing is retarded.

But I like doing homeworks ;_;

Theres a couple of libraries im unfamiliar with im trying to use what ive been taught so far.
thanks tho!

Can you do my concurrent homework then?
I'm almost finished now but the code is almost 500 lines long and doesn't have any comments.

>500 lines
Are you willing to pay?

>methods
they're functions you java brainlets

Nah, I already said I'm almost finished I just have some problems when synchronizing some of the threads but nothing I can't figure out, if you do my homework you'll save me like 2 hours but I'm retarded, you can probably do it in 15 minutes.

It's harder to fix code then to rewrite other people's code.

But user, I don't work on others' code, I do it myself, from the scratch

If I seriously can't figure it out, you'll probably see me posting in /dpt/ in the next days. Thanks anyway

ok.
Can you make a simple traffic system for me using threads?
there are only two intersections between the roads.

>functions
All these things, ("methods", """"functions"""") are actually fucking called procedures. Functions have a precise mathematical definition and nothing in any programming language matches this definition. "Methods" is a nonsense term for procedures made up by OOP shitters from the 90's.

Fucking CS babies and their shitty undisciplined field.

apps

Looks like you have a need for it. Nothing's for free, goy

>In mathematics, a function[1] is a relation between a set of inputs and a set of permissible outputs with the property that each input is related to exactly one output.

C/C++ functions are exactly the definition of a mathematical function.

bullshit. Math functions are ALWAYS pure

Not really, my teacher gave me a month to finish it but I almost finished in less than a day.

They're routines you C brainlets.

I started out with dev c++, it's light weight and good for learning but I would move on quickly when you get the basics

I just use notepad++ and MSYS2.

go away haskellfag

You wanna either store the random numbers in an array and then iterate through the array and print out the values or output them as you get them (in the function).

>not coding with punchcards
Learn how to use computers faggot

There is always a better way
#include
#include
#include

int main() {
std::array inputs, randoms;
std::generate(randoms.begin(), randoms.end(), std::rand);

std::generate(inputs.begin(), inputs.end(), []() {
int input;
std::cin >> input;
return input;
});

std::cout

Since you're most probably a student, get CLion, it's free for you.

>slow speed meme ended with python 3
yeah but "upgrading" from 2.7 to 3 means you lose compatibility with a TON of super useful but unfortunately dead libs.

...

It's been years now, basically every relevant lib is in python 3. What are you missing, supervisor?

If you're on Windows, Visual Studio is the only thing you should even consider.

If you don't want that, KDevelop is a close 2nd.

then why all performance critical software still written in C/C++?

Depends on what you mean by performance critical.
C/C++ are just the best tool in the box for things like DSP, embedded systems, etc.
There are other performance critical software programs. For instance, some of the largest sites in the internet with the heaviest traffic run on Python.
And it's fine, because on internet connected software the last thing is an accidental buffer overflow.

Can you explain in few words what changed so much that python 3 is no more slow meme?

I'll second using CLion if you're a student that can get it free. JetBrains' IDEs are in a league of their own.

Mostly iterators. That and internal optimizations to CPython in 3.6.
3 has a more consistent API that bites less too, so you are bound to make less mistakes.

You need to mode the random seed into main or else it will always return the same number.

NetBeans

Beginners should not use an IDE. A good text editor is very useful though.

tfw I can't convince my employer to buy clion for the team. God damn tightarse.

mfw tuitition is 3 times cheaper than the annual Jetbrains license and I only register to enjoy the student benefits.

that std::generate looks weird. why don't you use std::copy? imagine you'd want to change std::cin for a file. what would you do? open it outside and pass to lambda? like heck

K.

>open it outside and pass to lambda?
no, std::function

Woah dude do you mean to tell me that we can use the same terminology to mean different things in different fields????????? Kill yourself pseud

No, they clearly aren't. You can easily write a Check function that outputs the same thing given multiple different inputs.

you never declared an array to store variables
so you'd need:
int randomNum[5];
you also don't need the variable count.

What's wrong with int?

>Namespace std

What's wrong with this?

nothing as long as you don't do it in a header file

I use msys2 too but make sure to compile with the mingw64 terminal. Doing it with the msys2 terminal causes headaches you don't want.

my sides

the plain msys2 terminal is a Cygnus-like environment that links libc routines to its own wrapper "msys-2.0.dll", as MSYS2 is forked from cygnus anyway, but also allows native NT app development

...

>wangblows
>microshit shioffice
>mega outdated and no longer maintained IDE
>notepad++ and notepad in launcher
>chrome
>laptop
>asking a pleb tier question as a thread

are you 12

cygwin, wtf is cygnus

The point is that the msys2 terminal gives you linus standards with that wrapper. running those on windows(even in the msys2 terminal) will cause shit like newline to shit themselves.

ed to edit text
sh for ghetto makefiles
musl-gcc as compiler

dont listen to the other faggots suggesting clion. its a bloated piece of shit

exactly.

t. some guy that was around during the Cygnus Tech/Cygwin/RedHat transition period