Cyber9ja
Also any practice bokks for c++ for beginners?
C++ Primer C++By example Fundamentals of C++ Programming language
Cyber9ja
Welcome
Samuele
#include <SFML/Graphics.hpp> #include <time.h> using namespace sf; int N=30,M=20; int width = 600; int height = 600; int scl = 20; int dir, num = 1; struct Snake { int x,y;} s[100]; struct Apple { int x,y;} a; void Move(){ for (int i = num; i > 0; i--) { s[i].x=s[i-1].x; s[i].y=s[i-1].y; } if (dir==0){s[0].x+=scl;} if (dir==1){s[0].y-=scl;} if (dir==2){s[0].y+=scl;} if (dir==3){s[0].x-=scl;} if (s[0].x==a.x && s[0].y==a.y) { num++; a.x=rand()%scl; a.y=rand()%scl; } for (int i=num; i>0; i--) { if (s[i].x==a.x && s[i].y==a.y) { a.x=rand()%N; a.y=rand()%M; } } if (s[0].x>N) {s[0].x=0;} if (s[0].x<0) {s[0].x=N;} if (s[0].y>M) {s[0].y=0;} if (s[0].y<0) {s[0].y=M;} } int main() { srand(time(0)); RenderWindow window(VideoMode(width, height), "Snake"); RectangleShape rectangle(Vector2f(scl, scl)); RectangleShape rectapple(Vector2f(scl, scl)); Clock clock; float timer=0, delay=0.5; a.x=10; a.y=10; while (window.isOpen()) { float time = clock.getElapsedTime().asSeconds(); clock.restart(); timer+=time; Event e; while (window.pollEvent(e)) { if (e.type == Event::Closed) window.close(); } if (Keyboard::isKeyPressed(Keyboard::Left)) dir=1; if (Keyboard::isKeyPressed(Keyboard::Right)) dir=2; if (Keyboard::isKeyPressed(Keyboard::Up)) dir=3; if (Keyboard::isKeyPressed(Keyboard::Down)) dir=0; window.clear(Color::Black); window.display(); if (timer>delay) { timer=0; Move(); } // draw // window.clear(); for (int i=0;i<num;i++) { rectapple.setPosition(s[i].x*scl, s[i].y*scl); window.draw(rectapple); } rectangle.setPosition(a.x*scl, a.y*scl); window.draw(rectangle); window.display(); } return 0; }
Samuele
can anyone help me with this?
Samuele
when I run it I see squares that flash instead of a snake that moves normally
Erkin
Hello everyone, i study in Turkey and I know universities questions (projects) about intro the programming (or smth like that) in Turkey. And I want to see other countries. Can u share your project if u think yours is weird :D
معاذ
هاي
Anonymous
هاي
it's not arab 😂
I_Interface
هاي
speak English here
Nassrullah
Hi ! Anyone knows why the following code doesn't allow me to take 3 numbers each in a row ? using namespace std; #include <iostream> int main() { int N; N2; N3; cin >> N; cin >> N2; cin >> N3; } After "build and run", nothing happens when I enter a number and press the enter key. Thanks.
Nassrullah
You don't do anything else, only enter them. Try to use std::cout to print them and see a result.
Yes when I use cout to print them everything is ok and that's what i don't understand. I can't even enter the 3 numbers without using cout ! Why ?
I_Interface
Yes when I use cout to print them everything is ok and that's what i don't understand. I can't even enter the 3 numbers without using cout ! Why ?
Watch at your code. When you entered them, what's next ? End of the program. Nothing to do after the last std::cin.
معاذ
Nassrullah
Watch at your code. When you entered them, what's next ? End of the program. Nothing to do after the last std::cin.
The issue is that I can't even enter the 3 numbers. Ok let's add cout at the end like this : using namespace std; #include <iostream> int main() { int N, N2, N3; cin >> N; cin >> N2; cin >> N3; cout << "N3 = " << N3; } Still nothing happens.
M.Ridvan
Why every int divided by ;
M.Ridvan
int N, N2, N3;
Nassrullah
Why every int divided by ;
Oh my God ! Thanks.
Sinan
#include <iostream> using namespace std; int main() { int N, N2, N3; cin >> N; cin >> N2; cin >> N3; cout << "N3 = " << N3; }
Nassrullah
Why every int divided by ;
Thanks but it's not the problem. Indeed what i have written in my computer is ok (int N, N2, N3;) but i made the mistake only in my phone.
M.Ridvan
Hmm
M.Ridvan
You want to input all integer in a one row right?
Nassrullah
#include <iostream> using namespace std; int main() { int N, N2, N3; cin >> N; cin >> N2; cin >> N3; cout << "N3 = " << N3; }
This is exactly what i have written in my computer but I can't input each integer in a single row. That's the problem.
Nassrullah
Nassrullah
Nassrullah
Like this : 6 5 9
The input should be like this.
Nassrullah
No sorry.
M.Ridvan
cin >> N >> N2 >> N3;
M.Ridvan
Try this one
Nassrullah
cin >> N >> N2 >> N3;
With this one what I can do is the following input : 3 6 7 But I can't input like this : 3 6 7
Nassrullah
I want to be able to input one integer then press enter. Another integer then enter. Is that possible ?
Emir
With this one what I can do is the following input : 3 6 7 But I can't input like this : 3 6 7
cin >> n >> endl >> n2 >> endl >> n3; is that work?
Nassrullah
SOLVED The problem was my IDE(CodeLite). I have tried with the Terminal and it's ok.
معاذ
NXiss7
thx
Well, I've created many professional, commercial programs with backend and GUI, created unique encryption library that is available on all platforms, written optimized small programs for embedded devices, programmed bare metal microchips, used JNI to use C++ within Android applications... It has a wide area of use, you just select your areas of interest.
Anonymous
Hello. I have a question
Anonymous
I’m reading a file that has C-packed binaries. I can’t decode them normally. How can I unpack them? struct.unpack from python works for it.
Anonymous
b'MEI\x0c\x0b\n\x0b\x0e\x00L\x87\xda\x00L}\x02\x00\x00\n\x80\x00\x00\x00%Python\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
Anonymous
I need to turn this into readable text.
Anonymous
I would like to know whether there are any APIs to get memory usage application in VxWorks. It should give the following information: 1. Stack size used : 2. Heap size used : Please let me know if there are any other ways to find it.
Anonymous
Is there any way or any build in function through which I can get heap memory usage??
Anonymous
I used struct to unpack the binary representations
MengShu
Does anyone have experience with developing Windows Runtime API with C++/WinRT?
Anonymous
Define a cricket scoreboard class. It should have the innings details for both the teams, bowling analysis of bowlers, and list of wickets fallen. Design a presentation style such that any information can be seen easily. Use manipulators to achieve the effect. I need code for this in C++
Yasir
i have
Yasir
c++ quiz can u help me some questions
Samuele
#include <SFML/Graphics.hpp> #include <time.h> using namespace sf; int N=30,M=20; int width = 600; int height = 600; int scl = 20; int dir, num = 1; struct Snake { int x,y;} s[100]; struct Apple { int x,y;} a; void Move(){ for (int i = num; i > 0; i--) { s[i].x=s[i-1].x; s[i].y=s[i-1].y; } if (dir==0){s[0].x+=scl;} if (dir==1){s[0].y-=scl;} if (dir==2){s[0].y+=scl;} if (dir==3){s[0].x-=scl;} if (s[0].x==a.x && s[0].y==a.y) { num++; a.x=rand()%scl; a.y=rand()%scl; } for (int i=num; i>0; i--) { if (s[i].x==a.x && s[i].y==a.y) { a.x=rand()%N; a.y=rand()%M; } } if (s[0].x>N) {s[0].x=0;} if (s[0].x<0) {s[0].x=N;} if (s[0].y>M) {s[0].y=0;} if (s[0].y<0) {s[0].y=M;} } int main() { srand(time(0)); RenderWindow window(VideoMode(width, height), "Snake"); RectangleShape rectangle(Vector2f(scl, scl)); RectangleShape rectapple(Vector2f(scl, scl)); Clock clock; float timer=0, delay=0.5; a.x=10; a.y=10; while (window.isOpen()) { float time = clock.getElapsedTime().asSeconds(); clock.restart(); timer+=time; Event e; while (window.pollEvent(e)) { if (e.type == Event::Closed) window.close(); } if (Keyboard::isKeyPressed(Keyboard::Left)) dir=1; if (Keyboard::isKeyPressed(Keyboard::Right)) dir=2; if (Keyboard::isKeyPressed(Keyboard::Up)) dir=3; if (Keyboard::isKeyPressed(Keyboard::Down)) dir=0; window.clear(Color::Black); window.display(); if (timer>delay) { timer=0; Move(); } // draw // window.clear(); for (int i=0;i<num;i++) { rectapple.setPosition(s[i].x*scl, s[i].y*scl); window.draw(rectapple); } rectangle.setPosition(a.x*scl, a.y*scl); window.draw(rectangle); window.display(); } return 0; }
..
Emir
man 3 getrusage
#include <stdio.h> #include <string.h> #include <sys/resource.h> int main(){ int a = 10; printf("%d", a); int * b = malloc(sizeof(20)); *b = 20; printf("%d", b); getrusage(); } What are functions parameters?
Anonymous
why won't you type man 3 getrusage on your terminal
Emir
why won't you type man 3 getrusage on your terminal
i did, but i dont get it what paramater int who and struct rusage *r_usage
Ihor
hi guys who can help? I need to read array from file. And calculate number of letters. But must not be case sensitive.
Ihor
write code and share if it does not work. use pastebin )
i dont know how to realize calculating without register
Hermann
register?. c or c++?
Pavel
how😂😂
I don't do C, but there's something from Google https://stackoverflow.com/questions/2661766/how-do-i-lowercase-a-string-in-c/2661788
Erkin
how😂😂
Stdlwr function in stdlib.h
vkphrl
Hi everyone, could you help with the task, I just can’t come to a solution. It is necessary to read the text from the file, and output the amount of each letter (case insensitive) into the second file. Accordingly, the output of the text: "hello Honey" h: 2 o: 2 e: 2 l: 2 n: 1 y: 1
vkphrl
Like that if (( str[i] == 65 + counter ) || ( str[i] == 97 + counter )) {.... ??
Erkin
https://paste.ubuntu.com/p/cMHmmB65sP/
Erkin
Like this