help with pointers and DMA

I keep getting an error that says flyCatching not returning a value and cant figure out how to get pointers to work with arrays so that they return the values you want from them

Each contestant will be required to catch three flies, one at a time, in a 4’ by 4’ kitchen filled with food. The time, in seconds, to catch each fly will be recorded and averaged, and the contestant with the lowest average of the three times will be declared the winner (each fly must be caught within an hour using hands, not by mouth, but may be eaten after the corresponding time is recorded).

The program will have 2 functions:

the first function will accept the fly-catcher’s name and required number of flies, dynamically allocate an array of “int” elements, and have the user enter the fly-catcher’s three times and store them in the array using pointer notation. Prompt the user for the times with the fly-catcher’s name, and validate each time by placing it in a call to the second function. Then return the array to main.
the second function will validate that a time is greater than zero by accessing it with a pointer in the function header’s parameter list.


In main declare a pointer to a “double” variable named “average”. Then repeatedly have the user enter a contestant’s full name, have the program calculate the average time for the contestant using the pointer and the array returned from the first function (access the array by incrementing its address), and display the fly-catcher’s name and average time using the variable “average”. Then process the next fly-catcher (unknown number of fly-catchers).


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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<cctype>
#include<string>
#include<memory>

using namespace std;
void *flyCatching(int* []);

int main()
{
	const int SIZE = 3;
	int Times[SIZE];
	int i = 0; 
	int* Time2[SIZE] = { nullptr };
	for (int i = 0; i < 3; i++) 
	{	
		
		Time2[i] = &Times[i];
		void *flyCatching(&Time2[i]);
	}
	
	
	

	system("pause");
	return 0;

}

//the first function will accept the fly - catcher’s name and required number of flies, dynamically allocate 
//an array of “int” elements, and have the user enter the fly - catcher’s three times and store them in the array
//using pointer notation.Prompt the user for the times with the fly - catcher’s name, and validate each time by 
//placing it in a call to the second function.Then return the array to main.


void *flyCatching(int *Times[])
{
	string catcher;
	int Flies;
	const int SIZE = 3;
	int i = 0, newPlayer = 1;


	cout << "Enter catcher's full name \n";
	getline(cin, catcher);
	cout << "Enter the number of flies caught \n";
	cin >> Flies;
	cout << "enter the 3 times it took to catch the flies \n";

	while (newPlayer = 1) {
		cout << "Enter catcher's full name \n";
		getline(cin, catcher);

		for (int i = 0; i < 3; i++)
		{
		
			cin >> *Times[i];
		}

		cout << "Enter 1 for another player or press any key to exit \n";
		cin >> newPlayer;
	}
	
}

Last edited on
Strange program. What does it have to do with DMA?
honestly i have no idea. this teacher comes up with his own assignments and they are very hard i got a b in my last c++ class ill be lucky if i make it out of this one with a c
Your flyCatching function's signature expects you to return a void* pointer. You're currently not returning anything here. It sounds like you should be creating a dynamic array inside flyCatching, and returning its pointer to main. If you're allow to, change it to return int* and not void*.

e.g.
int* arr = new int[size];


void *flyCatching(&Time2[i]);
This is not calling a function, it's creating a variable called flyCatching of type void*.

while (newPlayer = 1) {
= is assignment
You want to use == here.
Last edited on
Topic archived. No new replies allowed.