help! im having trouble with cin input

im making a little program. if you type in the movie name project almanac then you will get a 38%. if you type in selma it gives you a 99%. some how if i type in selma it give me a 38% or sometimes when i changed it it gave me both percentages.

#include <iostream>

using namespace std;

int main()
{
char name[16] = {'P','r','o','j','e','c','t',' ','A','l','m','a','n','a','c','\0'};
char swag[6] = {'S','e','l','m','a','\0'};
cout << " enter movie of choice name" << endl;
cin >> name[16];
cin >> swag[6];
if (name[16] == name[16])
{cout << "38%" << endl;}
if (swag[6] == swag[6])
{cout << "99%" << endl;}





return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <map>

using namespace std;

int main ()
{
  string name = "Project Almanac";
  string swag = "Selma";
  string line;

  cout << "Enter movie of choice:";
  getline(cin, line);
  if (line == name)
    cout << name << " was selected" << endl;
  else if (line == swag)
    cout << swag  << " was selected" << endl;
  else
    cout << "Unknown movie: " << line << " was selected" << endl;

  return 0;
}
Topic archived. No new replies allowed.