Sourav
Ok
olli
I hope that wasn't another dumb question
Another issue: Given an array is passed to a function, how do you get the size?
BinaryByter
There's no way to store 256 in a char
If you watch the right movie, there is 😏
BinaryByter
MᏫᎻᎯᎷᎷᎬᎠ
Yeah
Hayk
Like you want it to automatically find you a bigger type to store it?
I can't understand. So.. I've checked and if I type char c = 256; cout << (int)c; then the output is 256.
Mihail
#include <iostream> using std::cout; int main() { char c = 256; cout << (int)c << '\n'; }
Mihail
Warnings: source_file.cpp:6:12: warning: implicit conversion from 'int' to 'char' changes value from 256 to 0 [-Wconstant-conversion] char c = 256; ~ ^~~ 1 warning generated. Result: 0 Tip: Wrap your code in triple backticks to display it in monospace.
Mihail
@hayk6
Hayk
I used cxxdroid
Mihail
I used cxxdroid
I used clang
Mihail
Not some noname compiler port
Anonymous
Hlw
Anonymous
Hlw
hi 😂🤟
klimi
hi
Matic
#include<iostream> #include<stdlib.h> #include<time.h> using namespace std; int fillArray(int arr[],int n){ for(int i=0;i<n;i++){ arr[i] = rand()%5; for(int j=0;j<n;j++){ while(arr[j] == arr[i]) arr[i] = rand()%5; } } } int main(){ int arr[5]; srand(time(0)); fillArray(arr,5); //print now for(int i=0;i<5;i++) cout<<" "<<arr[i]<<" "; }
Matic
why doesn't this run? just hangs
Matic
supposed to fill an array with non repetitive ints
Matic
should I use something else than that while loop?
Mihail
Also rand() is biased
Mihail
If it's C++ you should use a mt19937 for example
Mihail
Oh and fillArray should be void
Matic
My homework says I should compare both arrays in a function int compare(int generated[7], int input[7], int n)
Matic
and output the number count that are the same and the number itself
Matic
for example: 1. hit: 5
Matic
2. hit: 9
Matic
I know I can return the number count from the function but how would I manage the number itself to be printed in main?
MᏫᎻᎯᎷᎷᎬᎠ
Dude How do you know all that stuff?!!!!
MᏫᎻᎯᎷᎷᎬᎠ
MᏫᎻᎯᎷᎷᎬᎠ
Do what?
Know!!*
MᏫᎻᎯᎷᎷᎬᎠ
You can tell it to do so with constexpr xD
Matic
int hits_calc(int pc[7], int player[7], int n){ int hits = 0; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(pc[i] == player[j]) hits++; } } return hits; } int main() { srand(time(0)); int player[7]; int pc[7]; for(int i=0;i<7;i++) cout<<" "<<player[i]<<" "; cout<<endl; for(int i=0;i<7;i++) cout<<" "<<pc[i]<<" "; cout<<hits_calc(pc, player, 7)<<" zadetkov."; }
Matic
This now prints the number of hits
Matic
how would I print the hit itself in MAIN?
Matic
and I've left out the array fill functions
MᏫᎻᎯᎷᎷᎬᎠ
Wow
MᏫᎻᎯᎷᎷᎬᎠ
Yes it is
Asad
hi guys! i am just learning C++ and practising some code. now i just wanted to make a program that multiplies all numbers between 1 and 100 . but it gives me 0. why is this? is it beacause of my computer's hardware?
MᏫᎻᎯᎷᎷᎬᎠ
I thought you MUST pass a pointer
MᏫᎻᎯᎷᎷᎬᎠ
Yeah
Asad
Define an variable with a value 1
#include <iostream> int main() { int product = 1, value1 = 1; while (value1 < 100) { product = product * value1; value1 = value1 + 1; } std::cout << "\n\n The product of all numbers between 1 and 100 is " << product << std::endl; return 0; }
MᏫᎻᎯᎷᎷᎬᎠ
Define an variable with a value 1
Use that variable and multiple it with any variable and store the result of every multiplication operation
Asad
H̲i̲L̲e̲v̲e̲l̲
no. why?
Your nickname...
Andy
You can tell it to do so with constexpr xD
Clang also emits a UD2 where the function would fly off the end, thanks Clang
H̲i̲L̲e̲v̲e̲l̲
H̲i̲L̲e̲v̲e̲l̲
What compiler do you use?
Asad
does it matter
H̲i̲L̲e̲v̲e̲l̲
Delete this shit
MᏫᎻᎯᎷᎷᎬᎠ
You don't have to bring the source Everytime you give some informations xD
H̲i̲L̲e̲v̲e̲l̲
And install visual studio
Asad
And install visual studio
i think it aint free
H̲i̲L̲e̲v̲e̲l̲
Its free
H̲i̲L̲e̲v̲e̲l̲
Absolutely
Asad
Delete this shit
is it really shit.
H̲i̲L̲e̲v̲e̲l̲
I think yep
H̲i̲L̲e̲v̲e̲l̲
Or try your code in cpp.sh
Matic
I said I skipped the array filling part
Matic
I want to print out the number that is the same in main
Matic
and a function can't return 2 values
Matic
what should I do
Asad
Or try your code in cpp.sh
still the same answer
H̲i̲L̲e̲v̲e̲l̲
Use for()
MᏫᎻᎯᎷᎷᎬᎠ
Lol
Asad
dont understand you
MᏫᎻᎯᎷᎷᎬᎠ
Yeah I debuged it
H̲i̲L̲e̲v̲e̲l̲
dont understand you
Just try to use for
MᏫᎻᎯᎷᎷᎬᎠ
Lol
Asad
i dont know what you guys are talking about.... sorry i am new here