I need to make a loop that will make this program run again if the user chooses to do so but so far it hasn't been working out. I've been trying to make the loop and i have a slight idea of what it looks like but I can't seem to get it right. There's more to this program but I went ahead and shortened it.
#include <iostream>
#include <string>
usingnamespace std;
int main(void)
{
char response;
do
{
//// 1 Input Hand of Playing Cards ////
int x,y,z;
while ( true )
{
cout << "Enter value of cards in hand ranging from 1-13 and separated by spaces: " << endl;
cin >> x >> y >> z;
cin.ignore(999,'\n');
if ( cin.fail() )
{
cin.clear();
cin.ignore(999,'\n');
cout << endl;
cout << "Ivalid card values. Please try again." << endl;
cout << endl;
continue;
}
if ( x <= 0 || y <= 0 || z <= 0 )
{
cout << endl;
cout << "Card values not within given range. Please try again." << endl;
cout << endl;
continue;
}
if ( x > 13 || y > 13 || z > 13 )
{
cout << endl;
cout << "Card values not within given range. Please try again." << endl;
cout << endl;
continue;
}
break;
}
//// 2 Process Hand ////
//// 2.1 Identify Cards in Hand ////
int leastValueCard, medianCard, greatestValueCard;
if ( x <= y && y <= z )
{
leastValueCard = x;
medianCard = y;
greatestValueCard = z;
}
elseif ( x <= z && z <= y )
{
leastValueCard = x;
medianCard = z;
greatestValueCard = y;
}
elseif ( y <= z && z <= x )
{
leastValueCard = x;
medianCard = z;
greatestValueCard = x;
}
elseif ( y <= x && x <= z )
{
leastValueCard = y;
medianCard = x;
greatestValueCard = z;
}
elseif ( z <= x && x <= y )
{
leastValueCard = z;
medianCard = x;
greatestValueCard = y;
}
elseif ( z <= y && y <= x )
{
leastValueCard = z;
medianCard = y;
greatestValueCard = x;
}
//// Output Result ////
//// Three's ////
if ( x == x && y == x && z == x && x == 1)
{
cout << endl;
cout << "You have three Aces! " << endl;
}
elseif ( x == x && y == x && z==x && x== 13 )
{
cout << endl;
cout << "You have three Kings!" << endl;
}
elseif ( x == x && y == x && z==x && x== 12 )
{
cout << endl;
cout << "You have three Queens!" << endl;
}
elseif ( x == x && y == x && z==x && x== 11 )
{
cout << endl;
cout << "You have three Jacks!" << endl;
}
elseif ( x == x && y == x && z==x && x== 2 )
{
cout << endl;
cout << "You have three Twos." << endl;
}
elseif ( x == x && y == x && z==x && x== 3 )
{
cout << endl;
cout << "You have three Threes." << endl;
}
elseif ( x == x && y == x && z==x && x== 4 )
{
cout << endl;
cout << "You have three Fours." << endl;
}
elseif ( x == x && y == x && z==x && x== 5 )
{
cout << endl;
cout << "You have three Fives." << endl;
}
elseif ( x == x && y == x && z==x && x== 6 )
{
cout << endl;
cout << "You have three Sixes." << endl;
}
elseif ( x == x && y == x && z==x && x== 7 )
{
cout << endl;
cout << "You have three Sevens." << endl;
}
elseif ( x == x && y == x && z==x && x== 8 )
{
cout << endl;
cout << "You have three Eights" << endl;
}
elseif ( x == x && y == x && z==x && x== 9 )
{
cout << endl;
cout << "You have three Nines." << endl;
}
elseif ( x == x && y == x && z==x && x== 10 )
{
cout << endl;
cout << "You have three Tens." << endl;
}
//// Reinitiate Program ////
char response;
cout << endl;
cout << "Would you like to run the program again? (y/n)"
<< endl;
cin >> response;
cin.ignore(999,'\n');
return 0;
} while (response == 'y');
return 0;
}
Alright thanks for the uploading tips, I was wondering how to do that. Thanks. But now it's saying that the variable response is being used without being initialized. I tried fixing it but it wouldn't compile afterward