URGENT

Pages: 12
guys i´m doing a school work but this code have some mistake that i cant find
pls help me
(dont mind the phrases is Portugues)



#include <iostream>
#include <stdio.h>
#include <cstdlib>


int main()
{

int opcao;


cout<<"menu";
cout<<"opcao 1-Introduzir o numero de nomeações e premios de cada filme";
cout<<"opcao 2-Calcular o filme com mais nomeacoes";
cout<<"opcao 3-Calcular a media de prémios obtidos";
cout<<"opcao 4-Sair";

cin>>opcao;

if(opcao==1)
{
cout<<"intruduza o numero de nomeaçoes e premios de cada filme";

First, use code tags:



[code]

//Your Code Here

[/code]




Second, first issue is that your int main and if statements all have opening brackets and no closing brackets:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <stdio.h>
#include <cstdlib>


int main()
{

     int opcao;


     cout<<"menu";
     cout<<"opcao 1-Introduzir o numero de nomeações e premios de cada filme";
     cout<<"opcao 2-Calcular o filme com mais nomeacoes";
     cout<<"opcao 3-Calcular a media de prémios obtidos";
     cout<<"opcao 4-Sair";

     cin>>opcao;

     if(opcao==1)
     {
          cout<<"intruduza o numero de nomeaçoes e premios de cada filme";
     }
}
I would guess that

using namespace std;

is missing before main().
That too. I recommend you not put using namespace std and simply add std:: to the beginning of what needs it:


std::cout <<

std::cin >>
thank you mate
another question if you can answer me.
Now I need to do something like a vector to keep 5 diferent movie names to use later.
it would be like this?

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

#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
 
int main()
{
    
   int opcao;
   int[5] = (strar wars;star treck;avatar;home alone;et);

     cout<<"menu";
     
     cout<<"opcao 1-Introduzir o numero de nomeações e premios de cada filme";
     cout<<"opcao 2-Calcular o filme com mais nomeacoes";
     cout<<"opcao 3-Calcular a media de prémios obtidos";
     cout<<"opcao 4-Sair";

     cin>>opcao;

     if(opcao==1)
     {
          cout<<"intruduza o numero de nomeaçoes e premios de cada filme";
     }
}


and how i can associate this vector to a another vector?
Last edited on
I recommend you not put using namespace std and simply add std:: to the beginning of what needs it
Yes. But for a beginner it seems impossible to type this 5 additional letters and it is teached that way...

Line 11 may look like this:

const char *title[] = ("strar wars", "star treck", "avatar", "home alone", "et");

It is actually not a std::vector. It is an array.

and how i can associate this vector to a another vector?
Depends on what are you trying to do...
you almost have an array or an enum, its hard to tell which.

string variablename[5] = {"star wars", ...}; //note string type, variable for the array has a name, initial values are strings,...

or maybe you wanted an enum to use with an array?
enum movies {star_wars, star_trek, … maxmovies};

an array to enum association:
string variablename[maxmovies] = {"star wars", ...};
cout << variablename[star_trek]; //same as [1] but its named;

but you may be asking about something called parallel arrays, where the index is the same over several arrays (that is how you associate them)..

string names[5] = {….
int years[5] = {1972,...}
string directors[] = {"Lucas",}
...etc
and then [0] on each array in turn gets you everything about the first movie, [1] gets you everything about the second movie, etc.

vectors are object oriented arrays. Its a different thing; are you supposed to use them now?
Last edited on
It depends of if you're working with a fixed list, or if you want to add to/remove from the list while the program is running.

If you're working with a fixed list that won't be changed, you may use an array.
 
std::string[] = {"Star Wars", "Star Trek", "Avatar", "Home Alone"};
this is what i have to do:

B. Create a menu with the following options and program them:
i. Enter the number of nominations and awards for each film.
ii. Calculate the movie with the most nominations.
iii. Calculate the average of premiums obtained.
iv. Go out.

i think i need to do 3 arrays
Last edited on
It seems that each movie has 2 properties:
- name
- number of nominations
- number of awards.

If you've learned about structs then I'd put these three in a struct and make a single array of structs. Otherwise you could do 3 arrays, one for each property.

By the way, I find that this is a good approach to most problems: start with the data. Figure out what data you need. Then write the code for that data.
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
 
int main(int argc, char** argv)
{

      int n1,n2,n3,n4,n5;
      int opcao;
      int a,b,c,d,e;
      float media;
      char nomeacoes [5] = {n1,n2,n3,n4,n5};
      char premios [5] = {a,b,c,d,e};
      char filmes [5][30] = {"star wars","star treck","avatar","home alone","et"};

     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;

     cin>>opcao;
      
     if(opcao==1)
     {
          cout<<"intruduza o numero de nomeaçoes e premios de cada filme"<<filmes[0]<<endl;
           cout<<filmes[1]<<endl;
           cout<<filmes[2]<<endl;
           cout<<filmes[3]<<endl;
           cout<<filmes[4]<<endl;
          cin>>n1;
          cin>>n2;
          cin>>n3;
          cin>>n4;
          cin>>n5;
          cin>>a;
          cin>>b;
          cin>>c;
          cin>>d;
          cin>>e;
          
          
          cout<<"opcao 5-voltar ao menu";
          cin>>opcao;
     }
     
     if(opcao==2){
     	if(n1>n2 && n1>n3 && n1>n4 && n1>n5){
		 
     	  cout<<"o filme com mais nomeacoes e o star wars";
     }
     	  if(n2>n1 && n2>n3 && n2>n4 && n2>n5){
		   
     	   cout<<"o filme com mais nomeacoes e o star treck";
}
	    if(n3>n1 && n3>n2 && n3>n4 && n3>n5){
		  cout<<"o filme com mais nomeacoes e o avatar";
		  
		}
	   if (n4>n1 && n4>n2 && n4>n3 && n4>n5){
	   cout<<"o filme com mais nomeacoes e o home alone";
	   }
	    
	    if(n5>n1 && n5>n2 && n5>n3 && n5>n4){
	    	cout<<"o filme com mais nomeacoes e o et";
		}
	   
	 
	 
	 
	 
	 cout<<"opcao 5-voltar ao menu";
          cin>>opcao;
	 }
	 if(opcao==3){
	 
	 
	 
	 
	 
	 cout<<"opcao 5-voltar ao menu";
          cin>>opcao;
	 	
	 }
if(opcao==5){
	  
	  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 e premios obtidos"<<endl;
     cout<<"opcao 4-Sair"<<endl;
     cin>>opcao;
	  }
 }
     


i need help how can i show the highst number between 5 diferent ones?
(i try to do that in if(opcao==2))
Last edited on
If you mean how to find the biggest number, you have the right idea. If you want to output that highest number, you can add it to the if statements so each one outputs the variable it's checking.
but it didnt work...
but it didnt work...

What did it do? And with what input?
Process exited after 23.33 seconds with return value 0 just appear that

and i just put a random input like
1
2
3
4
5
6
7
8
9
0
try testing it with data that you understand what the output should be. If you do not know what the answer to the input is, you cannot know if the code did it right or not.

Last edited on
Well, first, on line 13 you try to add the values of integers into a character array. Moreover, those integers don't have any data in them because you just made them and didn't put anything in them.


Second, whether or not you n1-n5 variables get data in them is depedent on whether or not opcao is 1. So if the user enters 2, they'll never get to even put input into those variables.


So, you don't want these lines to be conditional:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
           cout<<filmes[1]<<endl;
           cout<<filmes[2]<<endl;
           cout<<filmes[3]<<endl;
           cout<<filmes[4]<<endl;
          cin>>n1;
          cin>>n2;
          cin>>n3;
          cin>>n4;
          cin>>n5;
          cin>>a;
          cin>>b;
          cin>>c;
          cin>>d;
          cin>>e;


You need to cin these variables before you can ever use them.


Next, it might be better to have each menu option into it's own function. So if the user inputs 1, they'd go to a function that does something. Then, you can loop through it until they enter 4 so they exit.


Finally, at the very least, turn those 2 char arrays into int arrays. And turn the final char array into a string array if you've gotten to strings.
I found that menu 2 and 3 are not working
I found that menu 2 and 3 are not working

This code shouldn't even compile
so what i need to do to fix this?
Pages: 12