My HS senior project test 1

hey all, i have this simple test program that is going to be the basis of my senior project for high school. I need some help. I wish to make a simple program that asks the user to input a champion's name from the game League of Legends. In this case, the user needs to input the name "kassadin". if they put in the name correctly the words" The Voidwalker" are displayed, otherwise "Invalid Champion Name, please try again" is displayed. I don't know how to correctly declare a variable that stands for the letter set or "kassadin". Some variable help is greatly appreciated too.

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
//Daniel Swanson
//Senior Project Test #1

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

int main()
{
	char inpKass = 'k' && 'a' && 's';
	char userInput = '""';

	cout << "Input champion name: ";
	cin >> userInput;

		if (userInput == inpKass)
		{
			cout << "The Voidwalker" << endl;
		}
		else
		{
			cout << "Invalid Champion Name, please try again" << endl;
		}
		
		system("pause");
	   return 0;

}


correct case
The Voidwalker


incorrect case
Invalid Champion Name, please try again
You can either use the character pointer or a string object.
1
2
char* test = "kassadin";
string test2("kassadin");


Same thing for the user input; however, either use a character array or the string object instead.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int main()
{
	char* inpKass = "kassadin";
	char* userInput = "";

	cout << "Input champion name: ";
	cin >> userInput;

		if (userInput == "kassadin")
		{
			cout << "The Voidwalker" << endl;
		}
		else
		{
			cout << "Invalid Champion Name, please try again" << endl;
		}
		
		system("pause");
	   return 0;

}


if i put in anything I get a huge error.

Unhandled exception at 0x771A016E (ntdll.dll) in seniorprojecttest1.exe: 0x00000000: The operation completed successfully.
You have userInput as a character array. Arrays have fixed sizes. In the case of userInput, it has a size of 0.

You should probably declare it as a string.
1
2
3
#include <iostream>
#include <iomanip>
using namespace std;


I think I may be missing a library type... Any help on this one?
#include <string>
Topic archived. No new replies allowed.