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:I need help revising my c++ code to allow me to error

Output for if I type something that isn't a number: check for if someone types in an invalid input like something that

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:25PM

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!