Mino
#include <iostream> #include <stdio.h> #include <vector> using namespace std; int main() { vector<float> t(10001); float simTime=10.0; float dt=0.001; for(int i=0; i<10001; i++) { float value=i*dt; t[i]=value; cout<<t[i]<<endl; } vector<float> i_a(t.size()); i_a[0]=0.0; double ka =3; double kb=2; double kc=1; int check; for (int i=0; i<10001;i++) { if (t[i]<0 || t[i]==0) { check=1; } else { check=0;} i_a[i+1]= i_a[i] + ( -(kb/ka)*i_a[i] + (kc/ka)*check)*dt; cout<<i_a[i]<<endl; } return 0; }
Mino
The code is ok, but I don't know because the value are wrong. The current should increase
Mino
The current has to reach 0.5
EMRE
write your question here
I want program to recursive mode the multiplication of the digit values ​​of the number entered by the user.
EMRE
your question?
How can I transfer the place values ​​of the number I wrote into the array?
Alex
use indexes of the array
Roshan
How can I transfer the place values ​​of the number I wrote into the array?
Reach the element in a for loop; Wherein increment the value of ( powerOfTen = 1 ) by 10 in each iteration. This is how you'll get the place value of a num. For ex:- in 1234, 2 -> 100 (the var value) which you can multiply with the digit
Anonymous
I am aware that there is no c# channel, but I could not find a channel to ask and ı wanted to get the opinions of those who know. Is there a youtube channel for c# that you can recommend? And for oop. Thanks..
Anonymous
@en_it_chats
Thanks :)
Goh Yong
/get cbook
Goh Yong
may i ask that whether the admin is a real person or a bot , or both
olli
may i ask that whether the admin is a real person or a bot , or both
Rose is a bot, you can tell by the username (@MissRose_bot)
Muhammed Bedir
Can I overloading << operator for ofstream and ostream at the same time?
Vlad
go figure
Muhammed Bedir
friend std::ostream& operator<<(std::ostream &sout, Hex &game); friend std::ofstream& operator<<(std::ofstream &fout,const Hex &game);
Muhammed Bedir
std::ofstream file(fname); file << this; file.close();
Muhammed Bedir
Vs says << is ostream type
Vlad
ostream is enough. Polymorphism, fren'
Muhammed Bedir
But declaration is different I mean output
Muhammed Bedir
std::cout << "OFSTEREAM " << std::endl; fout << "Id: " << game.getId() << std::endl; fout << "Size: " << game.getSize() << std::endl; fout << "Type: " << game.getType() << std::endl; fout << "Turn: " << game.getTurn() << std::endl; fout << "Winner: " << game.getWinner() << std::endl; fout << "Finish: " << game.getFinish() << std::endl; for (int i = 0; i < game.getSize(); ++i) { for (int j = 0; j < game.getSize(); ++j) { if (game.hexCells[i][j].getCell() != celltype::empty) fout << i << " " << j << " " << game.hexCells[i][j].getCell() << std::endl; } } return fout;
Muhammed Bedir
int c = 0; int free = 0; sout << "--------------------------------------------\n"; sout << "ID : " << game.getId() << " " << "Size : " << game.getSize() << " "; sout << "Type : " << game.getType() << " " << "Turn : " << game.getTurn() << " "; sout ; sout << "Winner: " << (char)game.getWinner() << " " << "finish :" << game.getFinish() << std::endl; sout << game.scoreOfUsers() << std::endl; sout << " "; for(char clm ='A' ;c<game.getSize();++c) sout << char(clm+c) << " "; sout << std::endl; for(int i=0; i<game.getSize(); ++i){ sout << i+1 << " "; for (int j = 0; j < free; ++j) sout << " "; for (int j= 0; j< game.getSize(); ++j) sout << char(game.hexCells[i][j].getCell()) << " "; sout << std::endl; free++; } sout << "=====================================\n"; return sout;
Vlad
You don't need both
https://godbolt.org/z/q4r76a
Vlad
Btw is it safe to take an address of cout?
Muhammed Bedir
https://godbolt.org/z/q4r76a
Thanks I guess it will work
Vlad
No?
I dunno that's why I'm asking, lol
Muhammed Bedir
😂😂
Vlad
I know that taking an address of std:: functions is ub(unless specified otherwise)
Muhammed Bedir
I guess these cout and cin adress is not change until program done
Roshan
Is sout << "......\n"; not cout??
Vlad
Muhammed Bedir
It is ostream string to assaign cout
Muhammed Bedir
I mean classic overload varible
Roshan
I guess it's a string stream
Not a stringstream I guess...
Muhammed Bedir
No it is not
olli
I know that taking an address of std:: functions is ub(unless specified otherwise)
are you sure? In the end a std::function is just another object you can take the address of. #include <functional> #include <cstdio> static void foo(int x, int y) { std::printf("%d, %d\n", x, y); } int main() { auto fn = std::bind(foo, 1, std::placeholders::_1); auto pfn = &fn; (*pfn)(123); }
Vlad
I mean classic overload varible
Everyone buckle up it's a variable overload
Vlad
lmao im dying
Vlad
Rather the functions that are within std:: namespace
olli
Hey Olli how do you write this in a copy-able format?
the monospace font? Use triple backticks, e.g. ``` code ```
labyrinth
if i were to define a list constructor like this, how am i gonna make it?
labyrinth
https://en.cppreference.com/w/cpp/container/unordered_map/unordered_map
labyrinth
i dont see the word list constructor but initialisation list,
HaiNahi
Anyone willing to make a hobby project with me ?
Pavel
if i were to define a list constructor like this, how am i gonna make it?
What does list constructor mean? Can you give an example?
labyrinth
// list constructor std::unordered_map<int, std::string> m2 = { {1, "foo"}, {3, "bar"}, {2, "baz"}, };
labyrinth
from cpp reference
labyrinth
in addition, i came across template<T> mystruct<T*> which i cannot understand
labyrinth
an example of this would be std::hash, where there are lot of variants for the basics type
Pavel
// list constructor std::unordered_map<int, std::string> m2 = { {1, "foo"}, {3, "bar"}, {2, "baz"}, };
Yes, then constructor with std::initializer_list is what you need. Note that for the objects that will be cunstructed (like std::pair in the example of map) their constructors with multiple arguments should not be marked as explicit to be constructed with {}
Pavel
an example of this would be std::hash, where there are lot of variants for the basics type
std::hash is another animal as I understand Do you need your arguments from which you construct your class to be all the same (as with map) or they can be different (as with tuple)? Should the type of the object change from the arguments (like std::pair, std::tuple)?
Pavel
Because in case of the map, initializer_list can help to pass objects that will be stored in the container, but these will not affect type as far as I remember. And pair and tuple are made with templates so their type depends on every element of the constructor
Roshan
int main(){ static int n = 1; if(cout<<n<<" " && n++ < 10 && main()) {} }
Roshan
Can you do any better?
Pavel
int main(){ static int n = 1; if(cout<<n<<" " && n++ < 10 && main()) {} }
You don't need static for local variables in main. You should not do anything but checks inside if check, so don't put cout << there. You should not call main directly, it's a special function.
HaiNahi
Printf better I am in android my laptop out somewhere I have termux any idea for command line projects
Xudoyberdi
I should learn more
HaiNahi
I am a high school student the last project I made is a chess engine
HaiNahi
I am also not pro