Question
I need help revising my c++ code to allow me to error check for if someone types in an invalid input like something that isn't
I need help revising my c++ code to allow me to error check for if someone types in an invalid input like something that isn't a number like a char or a string using cin ignore and/or cin clear. Please follow the example as closely as possible and follow all instructions.
Assignment Details & Example:
Output for if I type something that isn't a number:
My code:
#include
#include
using namespace std;
int main() {
string suits[] = { "Hearts", "Diamonds", "Spades", "Clubs" };
string ranks[] = { "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace" };
int index;
cout
cin >> index;
cout
//asking for one more time
cout
cin >> index;
//displaying rank and suit, assuming inputs are valid
cout
return 0;
}
Assignment Create an array of 52 cards. The 52 cards all contain a value and a suit based on its array position. The value starts with 2, 3, 4, 5,6,7,8, 9, 10, J (Jack), Q (Queen), K (King), A (Ace). Suits will be: Hearts, Diamonds, Spades, and Clubs. Your job is to determine the value and suit of a card in the single-dimensional array without using any other arrays. You must use the order given to you above (2 comes before 3, Hearts comes before Diamonds). The array is keyed first on the value, then the suit. So all heart cards will come first, then diamonds, then spades, and finally, clubs. For this mini-lab, the array itself will not store a relevant value. However, for the lab, it will. Example Enter a card index:0 That's the 2 of Hearts Enter a card index: 1 That's the 3 of Hearts Submission Submit your cpp file. tshahid: tesLa8~./mlab7 Enter a card index: u That's the 2 of Hearts Enter a card index: That's the 2 of Hearts 2:25PMStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started