URGENT

Pages: 12
Read my post where I tell you what's wrong.

You're not putting anything into those variables when you try to use them. If you input "2", then how will n1-n5 have any values? You shouldn't make those cin >> lines conditional.
Hello joao2002,

To put it differently than zapshe did.

Line9 defines the variables, but they are uninitialized and only contain a garbage value, so when you try to use them on line 13 you are using garbage values when setting the elements of the array.

You might consider this as a start:
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
66
67
68
69
70
71
72
73
#include <iostream>
#include <string>
//#include <stdio.h>  // <--- Not needed. C header file for I/O. Covered with "iostream". Pluss there is not C I/O code in the program.
//#include <cstdlib>  // <--- Not needed. Maybe later.

//using namespace std;  // <--- Best not to use.
// The most recent post that is worth reading. http://www.cplusplus.com/forum/beginner/258335/
//  An alternative.
using std::cin;
using std::cout;
using std::endl;
using std::string;

int main(/*int argc, char** argv*/)  // <--- If you are not going to use them you do not need them.
{
        // <--- Numbers used to initialize the variables only. They have no real use.
	int nome1{ 1 }, nome2{ 2 }, nome3{ 3 }, nome4{ 4 }, nome5{ 5 };  // <--- Variables need to be initialized. Variaveis precisam ser inicializadas.
	int opcao;
	int award1{ 1 }, award2{ 1 }, award3{ 1 }, award4{ 1 }, award5{ 1 };  // <--- Variables need to be initialized. Variaveis precisam ser inicializadas.
	double media;
	int nomeacoes[5] = { nome1, nome2, nome2, nome4, nome5 };     // <--- Changed.
	int premios[5] = { award1, award2, award3, award4, award5 };  // <--- Changed.
	char filmes[5][30] = { "star wars", "star treck", "avatar", "home alone", "et" };  // <--- Should be a std::string.

	//cout << "menu" << endl;
	//cout << "opcao 1-Introduzir o numero de nomeacoes e premios de cada filme" << endl;
	//cout << "opcao 2-Calcular o filme com mais nomeacoes" << endl;
	//cout << "opcao 3-Calcular a media de premios obtidos" << endl;
	//cout << "opcao 4-Sair" << endl;

	// Or, you may find that this works better. Ou, voce pode achar que isso funciona melhor.
	cout
		<< "\n" << string(25, ' ') << "MENU\n\n"  // <--- Creates 25 spaces.
		<< "opcao 1-Introduzir o numero de nomeações e premios de cada filme\n"
		<< "opcao 2-Calcular o filme com mais nomeacoes\n"
		<< "opcao 3-Calcular a media de prémios obtidos\n"
		<< "opcao 4-Sair\n"
		<< "Enter Choice: ";

	cin >> opcao;

	if (opcao == 1)
	{
		cout << "intruduza o numero de nomeaçoes e premios de cada filme\n";  // <--- Changed.
		cout << filmes[0] << endl;  // <--- Changed.
		cout << filmes[1] << endl;
		cout << filmes[2] << endl;
		cout << filmes[3] << endl;
		cout << filmes[4] << endl;

                // <--- Could use.
                //cout
                //    << filmes[0] << '\n'
	        //    << filmes[1] << '\n'
                //    << filmes[2] << '\n'
                //    << filmes[3] << '\n'
                //    << filmes[4] << '\n';
	
		// <--- All these need a prompt to know what to enter. Tudo isso precisa de um prompt para saber no que inserir.
		cin >> nome1;
		cin >> nome2;
		cin >> nome2;
		cin >> nome4;
		cin >> nome5;
		cin >> award1;
		cin >> award2;
		cin >> award3;
		cin >> award4;
		cin >> award5;

		//cout << "opcao 5-voltar ao menu";  // <--- Needs to be in a loop to make use of this and it is not needed here. Precisa estar em um loop para fazer uso disso e nao e necessário aqui.
		//cin >> opcao;
	}

AS said work with this first and get it working before you move on to something else.

Andy
Hello joao2002,

When I started working on the if statement for 1 I discovered a few things.

The variables "n1 - n5" and "a - e" are not needed. You enter values for these variables, but these values should go into the array.

To give you an idea:
1
2
3
4
5
6
7
8
9
if (opcao == 1)
{
	//cout << "intruduza o numero de nomeaçoes e premios de cada filme\n";  // <--- Changed.
	cout << "\n Enter the number of nominations and awards for each film\n";  // <--- So I could understand better.

	cout << "\n Filme: " << filmes[index] << " nomeacoes: ";  // <--- Changed.
	cin >> nomeacoes[index];
	cout << " premios: ";
	cin >> premios[index++];

Sorry if my translations are a bit off, but I was going partly by the variable names.

As I looked at the code further I realized that you have created arrays that are never used. You need to decide on what you want to use. Variables or arrays?

Andy
Topic archived. No new replies allowed.
Pages: 12