loops and arrays


Hey,

ive just started learning c++ assembly, kinda getting the hang of it but ive got stuck on loops and arrays working together.

Basically i've got to make a script which will take 4 inputted values store them in an array and then the script will work out the average out of the in putted numbers.

heres what i got so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <stdafx.h>

int main (void)
{
	int mark1[] = "Enter the Mark for Module:";
	char average[] = "The average mark is:";
	char format[] = "%d"; 

	int myarray[4]; 
	myarray[0] = test1; 
	myarray[1] = test2; 
	myarray[2] = test3; 
	myarray[3] = test4; 

	_asm {
	mov ecx,4 
	mov eax,0 
	mov ebx,0 
	Loop1: add eax,myarray[ebx] 		
	add ebx,4
	loop Loop1
	... }
}
 Sleep(99999999);
return 0;
}


If someone could point me in the right direction that would be great!

Thanks

~Crag
This topic shows a example of a code with loops and arrays, though I not sure if it'll help.
http://www.cplusplus.com/forum/beginner/32206/

@Offtopic
How does that Sleep function work ? :D
Is it just a loop that keeps your prog busy for a few sec? (if thats the case , there would be a lot better replacements :D)
or does it really count in miliseconds or something?
okay guys im really stuck on this and i need help badly. All i know is that i need a loop at the begining to ask for four different marks, these marks have to be between 0-100. the marks are then stored in array and then i do a sum such as SAR EAX,2 to work out the average mark.

If you guys could help that would be great!

@offtopic
it counts down so you are able to see outputs etc

Thanks,

~Crag
what's your problem exactly?

What I can tell is that 'loop' will be endless because there's no jump out
im just stuck full stop, my main problem is putting user inputs into arrays! if you could show me source code of this happening that would be great!
Cragsterboy wrote:
my main problem is putting user inputs into arrays!
you mean something like that?
1
2
3
4
5
6
7
#include <iostream>
...
  for(int i = 0; i < (sizeof(myarray) / sizeof(*myarray)); ++i)
  {
    std::cout << "Enter the Mark " << i << " for Module:" << std::endl;
    std::cin >> myarray[i];
  }


EDIT: remove line 8 from your code it's just wrong
Last edited on
Topic archived. No new replies allowed.