lundi 9 octobre 2017

Why is my If statement being ignored in C++? [on hold]

I have to write this program that spits out information based on the character entered. I have the string down pat and it seems like my program is working for the most part, but for some reason no matter what character I input, it only executes the first line, and gives me info for TV. I can't figure out why it ignores the if statement and just outputs , TV, and FREE no matter what character is given. Source code's here:

#include <iostream>
#include <string>
using namespace std ;

int main()
{
  string title ;
  int rdate ;
  char code ; 
  cout << "Enter title: " ;
  cin >> title ;
  cout << "Enter viewing code (T, N, or M): " ;
  cin >> code ;
  if (code == 't', 'T')
    {
      cout << title << endl << "Type: TV" << endl << "Price: FREE" << endl ;
    }
  else if (code == 'n', 'N')
    {
      cout << title << endl << "Type: New Release" << endl << "Price: $6.99" << endl ;
    }
  else if (code == 'm', 'M')
    {
      cout << "Enter year of release: " ;
      cin >> rdate ;
      if (rdate <= 1959)
        {
         cout << title << "(" << rdate << ")" << endl << "Type: Movie" << endl << "Price: $2.99" << endl ;
        }
    } 
  else cout << "Invalid Input." << endl ;      

  return 0 ;
}

An example of what I get when I try to execute:

Enter title: TESTTITLE
Enter viewing code (T, N, or M): P
TESTTITLE
Type: TV
Price: FREE

Aucun commentaire:

Enregistrer un commentaire