<script src="http://pastebin.com/embed_js.php?i=wN0E3tjz"></script>
Code:
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- int main()
- {
- typedef struct
- {
- double x, y, z;
- int protons, neutrons, electrons, speed;
- }
- atom;
- void move(atom someatom)
- {
- someatom.x+=1;
- }
- int main()
- {
- //initialize the atom
- atom helium;
- helium.x = 0;
- helium.y = 0;
- helium.z = 0;
- helium.protons = 2;
- helium.neutrons = 2;
- helium.electrons = 2;
- int time = 0;
- double speed = 1;
- //move in a straight line 100 units along the x axis
- int i;
- for (i = 0; i < 100; i+=speed)
- {
- time++;
- move(helium);
- printf("time = %d: (%d,%d,%d)", time, helium.x, helium.y, helium.z);
- }
- //bounce in the box
- double dx = 1, dy = 2, dz = 3; // these values represent the velocity vector, change these to speed up or slow down.
- while (true)
- {
- atom.x += dx; //move the atom
- atom.y += dy;
- atom.z += dz;
- if (atom.x > 100 || atom.x < 0)
{
- atom.x -= dx; // move back to before it hit
- dx *= -1; // change the direction to bounce
- }
- if (atom.y > 100 || atom.y < 0) {
- atom.y -= dy; // move back to before it hit
- dy *= -1; // change the direction to bounce
- }
- if (atom.z > 100 || atom.z < 0) {
- atom.z = dx; // move back to before it hit
- dz *= -1; // change the direction to bounce
- }
- }
- return 0;
- }
- My Problems:
line 54: atom.x += dx;
it says: syntax error before '.' token
line 58: if(atom.x>100|| atom.x<0)
it says: syntax error before 'atom'
I really appreciate the help since I am in a beginning programming class. I have NEVER coded. I'm sorry if the problems are super obvious and my code is messy, but I would love if you could make my code work for C programming. I'm using the compiler bloodshed. I'm trying to make the 'atom' bounce off the 'jar's' walls in this code. Thank you!!