SOS Please I have 1 error I can't see it! :(

I want to make columns of N names and N scores.


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
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int rand_0toN1(int n);
void draw_the_list();
char *names[3] = { "L. Maimouna", "M. Antony", "H. Hamissou" };
char *scores[3] = { "94", "99", "100" };

int main()
{
	int n;
	int i;
	srand(time(NULL));
	while (1)
	{
		cout << "Enter the list number to draw a name.";
		cout << "(o to exit):";
		cin >> n;
		if (n == 0)
			break;
		for (i = 1; i <= n; i++)
			draw_the_list();
	}
	return 0;

	void draw_the_list()
	{
		int u;
		int s;
		u = rand_0toN1(3);
		s = rand_0toN1(3);
		cout << names[n] << "of" << scores[s] << endl;
	}
	int rand_otoN1(int n)
	{
		return rand() % n; // It tells me n is not declared but I did in main
	}
}
Last edited on
closed account (z05DSL3A)
The } on line 41 should be on line 28
I am now getting two errors.


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
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int rand_0toN1(int n);
void draw_the_list();
char *names[3] = { "L. Maimouna", "M. Antony", "H. Hamissou" };
char *scores[3] = { "94", "99", "100" };

int main()
{
	int n;
	int i;
	srand(time(NULL));
	while (1)
	{
		cout << "Enter the list number to draw a name.";
		cout << "(0 to exit):"; // I hope it was another error, I put o instead of zero.
		cin >> n;
		if (n == 0)
			break;
		for (i = 1; i <= n; i++)
			draw_the_list();
	}
	return 0;
}

	void draw_the_list()
	{
		int u;
		int s;
		u = rand_0toN1(3);
		s = rand_0toN1(3);
		cout << names[n] << "of" << scores[s] << endl;
	}
	int rand_otoN1(int n)
	{
		return rand() % n;
	}
line 36 - did you mean to use u or s instead of n? n isn't defined in the draw_the_list function

edit:

1
2
3
4
u = rand_0toN1(3);
s = rand_0toN1(3);
int rand_0toN1(int n);
int rand_otoN1(int n) // <- typo in function name 
Last edited on
closed account (z05DSL3A)
IAandEEBLKFMA wrote:
I am now getting two errors.
It would be helpful to all concerned if you actually say what the errors you get are. We can explain what the error means and where to look to fix it.
I think I made it worse. I don't understand your explanations.

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
#include <iostream>
#include <ctime>
#include <cmath>
using namespace std;

int rand_0toN1(int n);
void draw_the_list();
char *names[3] = { "L. Maimouna", "M. Antony", "H. Hamissou" };
char *scores[3] = { "94", "99", "100" };

int main()
{
	int n;
	int i;
	srand(time(NULL));
	while (1)
	{
		cout << "Enter the list number to draw a name.";
		cout << "(0 to exit):"; // I hope it was another error, I put o instead of zero.
		cin >> n;
		if (n == 0)
			break;
		for (i = 1; i <= n; i++)
			draw_the_list();
	}
	return 0;
}

void draw_the_list()
{
	int u;
	int s;
	u = rand_0toN1(3);
	s = rand_0toN1(3);
	int rand_otoN1(int u);
	int rand_otoN1(int s);
	cout << names[n] << "of" << scores[s] << endl;
}
int rand_otoN1(int n)

{
	return rand() % n;
}



The errors:

Warning 1 warning C4627: '#include <iostream>': skipped when looking for precompiled header use

Warning 2 warning C4627: '#include <ctime>': skipped when looking for precompiled header use

Warning 3 warning C4627: '#include <cmath>': skipped when looking for precompiled header use


Error 4 error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?



5 IntelliSense: expected a ';'
6 IntelliSense: expected a declaration


Last edited on
Sorry if I confused you. I just copied in lines of your code to show the discrepancy in spelling. line 38 - you spell the function name differently there.

int rand_otoN1(int n) // <- typo in function name


You don't need all those lines in the function.

1
2
3
4
5
6
7
8
9
10
void draw_the_list()
{
	int u;
	int s;
	u = rand_0toN1(3);
	s = rand_0toN1(3);
	int rand_otoN1(int u);
	int rand_otoN1(int s);
	cout << names[n] << "of" << scores[s] << endl;// <- this function doesn't know what n is. Did you mean to use one of the local variables you actually defined in the function? 
}
I made n global got more errors.
You could just pass it to the function like you do here. int rand_0toN1(int n) Making variables global isn't always the best idea.

Then why do you define both u and s in this function if you only use s?
I added #include <cstdlib> got it now! Thanks a lot for time and explanations @wildblue, and @ Grey Wolf!!!!

it runs but I only get one name the first one. The scores don't even show up.
Last edited on
Topic archived. No new replies allowed.