#include <algorithm>
#include <iostream>
#include <Windows.h>
#include <string>
#include <cctype>
using namespace std;

int main(void)
{
	//declare variables
	char npcname;
	char actid;

	//askin the user to input npc name
	cout << "Please Enter Your NPC Name!"<<endl;
	cin >> npcname;
	//askin the user to input action id
	cout << "Please Enter Your NPC ActionID!"<<endl;
	cin >> actid;
	while (!isdigit(actid))
	{
		cout << "You must enter a number for your ActionID"<<endl;
		cin>> actid;
	}

	cout <<"worked";


}

when i type the NPC name it's check if the npcname is digit or not while the while loop should check if the accid is digit or not HOW COME -.-!!!?

Edited 5 Years Ago by Mr_PoP: n/a

You're working with single characters rather than strings. Try changing the type of npcname and actid from char to std::string. Also note that the loop won't work too well with strings. You probably want to check all characters.

Edited 5 Years Ago by Narue: n/a

You're working with single characters rather than strings. Try changing the type of npcname and actid from char to std::string. Also note that the loop won't work too well with strings. You probably want to check all characters.

#include <algorithm>
#include <iostream>
#include <Windows.h>
#include <string>
#include <cctype>
using namespace std;

int main(void)
{
	//declare variables
	string npcname;
	string actid;

	//askin the user to input npc name
	cout << "Please Enter Your NPC Name!"<<endl;
	cin >> npcname;
	//askin the user to input action id
	cout << "Please Enter Your NPC ActionID!"<<endl;
	cin >> actid;
	while (!isdigit(actid[0]))
	{
		cout << "You must enter a number for your ActionID"<<endl;
		cin>> actid;
		cout << actid;
	}

	cout <<"worked";


}

worked bt if i typed a number at the beging it will work how can i stop it?

Edited 5 Years Ago by Mr_PoP: n/a

You also may want to read up on strings and string input, from what I read from multiple other sources, you want to be using the standalone function getline(cin, npcname) vs the regular cin >> input. Mixing cin >> with strings may give some funky results.

This question has already been answered. Start a new discussion instead.