Functions in switch

Im trying to write a program where the user enters a viewing code and get a cost and the viewing code back. Im trying to use functions as its part of the project but i cant seem to get it. What am I missing? I get no values back and get lots of errors.

/*Program: prog2B.cpp
By: Irvin Florencia
Last Modified: October 20,2017
Purpose: Display price of viewings.
*/

//Directives
#include<iostream>
#include<string>

using namespace std;

void tv();
void brandNew();
int oldMovies(int year);
void displayResults();

int main()
{
char code;
string title, cost, viewing;
int year ;
void brandNew();
int oldMovies(int year);
void displayResults();

cout << "Enter Title: " ;
getline (cin, title);
cout << "Enter code: " ;
cin >> code ;

switch (code)
{
case 't': case 'T':
void tv();
break;

case 'n': case 'N':
void brandNew();
break;

case 'm': case 'M':
int oldMovies(int year);
break;
}

}

void brandNew()
{
string cost, viewing;
cost = "$6.99" ;
viewing = "New Release" ;

void tv()
{
string cost, viewing;
cost = "FREE";
viewing = "TV";
}

int oldMovies (int year)
{
string cost, viewing
cout << "Enter year: " ;
cin >> year ;

if (year < 1960)
{ cost ="$2.99";
viewing ="Non new release";
}

else if (year <1979)
{ cost ="$3.99";
viewing = "Non new release";
}

else if ( year < 1999)
{ cost = "$4.99" ;
viewing = "Non new release";
}

else ( year > 2000)
{ cost = "$5.99";
viewing = "Non new release";
}

}

void displayResults()
{
string cost, title, viewing;

cout << "Title: " << title << endl;
cout << "Viewing: " << viewing << endl;
cout << "Amount due: " << cost << endl;
}

1) Where does brandNew()'s block end? There is no closing brace.

2) In the function int oldMovies(int year) the declaration of cost and viewing is missing a semi-colon at the end.

3) if and if else statements allow you to state conditions but that is not allowed in else statements. An else is what the program goes for when it is completely out of possible options, so the last possible condition is embedded in the else statement. As you can see in the else statement in the function oldMovies(int year) you have tried to give a condition for the else statement.

4) You are not using year, the int variable you declared in main().

5) And why doesn't oldMovies(int year) return anything while it is declared as an int returning function?

P.S. For the sake of readability, put your code in code blocks. Select edit, select your hole code then click on '<>' from the menu of formats provided.
Last edited on
Topic archived. No new replies allowed.