Click here to Skip to main content
15,895,962 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I had to adjust my already working code to use functions. I tried to change things and it compiles, but when I input the code and title, nothing happens. There is no output.

1 */
2 #include <iostream>
3 using namespace std ;
4 int main()
5 {
6 string title ;
7 char code ;
8 int year ;
9 float cost ;
10 cout << "Enter the code of viewing and the title of the viewing. (Separated by a 11 space; either T, M, or N" << endl ;
12 cin >> code >> title ;
13 switch (code)
14 {
15 case 'T':
16 case 't':
17 string TV (char code, string title) ;
18 break ;
19 case 'N':
20 case'n':
21 string NewRel (char code, string title) ;
22 break ;
23 case 'M':
24 case 'm':
25 string Movie (char code, string title) ;
26 break ;
27 default:
28 cout << "error" << endl ;
29 }
30 return 0 ;
31 }
32 string TV (char code, string title)
33 {
34 float cost = 0 ;
35 string type = "TV" ;
36 return type ;
37 return title ;
38 return cost ;
39 }
40 string NewRel (char code, string title)
41 {
42 float cost = 6.99 ;
43 string type = "New Release" ;
44 cout << title << endl ;
45 cout << type << endl ;
46 cout << "$" << cost << endl ;
47 }
48 string Movie (char code, string title)
49 {
50 int year ;
51 float cost ;
52 string type = "Movie" ;
53 cout << "Enter year of movie" << endl ;
54 cin >> year ;
55 if (year < 1960 )
56 {
57 cost = 2.99 ;
58 cout << title << endl ;
59 cout << type << endl ;
60 cout << "$" << cost << endl ;
61 }
62 else if (year < 1980)
63 {
64 cost = 3.99 ;
65 cout << type << endl ;
66 cout << "$" << cost << endl ;
67 }
68 else if (year < 2000)
69 {
70 cost = 4.99 ;
71 cout << title << endl ;
72 cout << type << endl ;
73 cout << "$" << cost << endl ;
74 }
75 else if (year > 2000)
76 {
77 cost = 5.99 ;
78 cout << title << endl ;
79 cout << type << endl ;
80 cout << "$" << cost << endl ;
81 }
82 else
83 {
84 cout << "No movies from the year 2000." << endl;
85 }
86 }

What I have tried:

I have tried adjusting different parts. I tried to look up my question to see if anyone else has asked about the same thing. Also, sorry I didn't know how to enter this with the numbers, so I just typed them.
Posted
Updated 22-Oct-17 10:09am

1 solution

Quote:
string TV (char code, string title)
{
float cost = 0 ;
string type = "TV" ;
return type ;
return title ;
return cost ;
}

Sorry, I can't believe the compiler (and a human either) could accept the above code: return cost; is just plain wrong, the function must return a string instead of a float.

[update]
A working (though incomplete) code
C++
#include <iostream>
using namespace std;

// .. other function declarations 
void Movie (char code, string title);

int main()
{
  string title;
  char code; 
  cout << "Enter the code of viewing and the title of the viewing. (Separated by a 11 space; either T, M, or N" << endl;
  cin >> code >> title;
  switch (code)
  { 
  //.. other cases
  case 'M':
  case 'm': 
    Movie(code, title);
  break ; 
  default: 
  cout << "error" << endl ;

} 
return 0 ;
}
// .. other function definitions
void Movie (char code, string title)
{
  int year ;
  float cost ;
  string type = "Movie" ;
  cout << "Enter year of movie" << endl ;
  cin >> year ;
  if (year < 1960 )
  {
    cost = 2.99 ;
    cout << title << endl ;
    cout << type << endl ;
    cout << "$" << cost << endl ;
  }
  else if (year < 1980)
  {
    cost = 3.99 ;
    cout << type << endl ;
    cout << "$" << cost << endl ;
  }
  else if (year < 2000)
  {
    cost = 4.99 ;
    cout << title << endl ;
    cout << type << endl ;
    cout << "$" << cost << endl ;
  }
  else if (year > 2000)
  {
    cost = 5.99 ;
    cout << title << endl ;
    cout << type << endl ;
    cout << "$" << cost << endl ;
  }
  else
  {
    cout << "No movies from the year 2000." << endl;
  }
}

[/update]
 
Share this answer
 
v2
Comments
Member 13479017 22-Oct-17 16:14pm    
Like I stated up above, I looked up and tried different things I saw online. As you can see, that was only one of the three sections I have.
CPallini 22-Oct-17 16:27pm    
OK, but in order to see any output your code must compile.
Member 13479017 22-Oct-17 16:30pm    
It does.
CPallini 22-Oct-17 16:38pm    
Please, see my updated solution.
Member 13479017 22-Oct-17 16:48pm    
I looked and changed what you did. It still is not producing an output and I am not sure why. Thank you for helping me though.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900