4-card poker
Prompt the user, input 4 fixed point values, which can be input in any order.
C&d on input failure.
Each of the 4 numbers is supposed to be in the range [1, 13], otherwise c&d.
Output the appropriate one of the following 5 messages:
4 of a kind
3 of a kind
two pairs
one pair
nothing
For example, if the input were
5 5 1 5
then your program would output
3 of a kind
I don't know what I did wrong in my code and i'm stuck please help
#include<iostream>
#include <cstdlib>
#include <string>
using namespace std;
bool die(const string & msg);
int main() {
unsigned c0, c1, c2, c3;
cout << "Please enter 4 cards in[1,13]:
";
cin >> c0;
if (!cin) die("Input Failure");
if (c0 < 1 || c0 > 13) die("Out Of
Range");
cin >> c1;
if (!cin) die("Input Failure");
if (c1 < 1 || c1 > 13) die("Out Of
Range");
cin >> c2;
if (!cin) die("Input Failure");
if (c2 < 1 || c2 > 13) die("Out Of
Range");
cin >> c3;
if (!cin) die("Input Failure");
if (c3 < 1 || c3 > 13) die("Out Of
Range");
cout << c0 << " " << c1 << " " << c2 << " " << c3 << endl;
if (c1 == c3)
cout << "There are 4 of a
kind. \n";
else if (c0 == c1 || c1 == c2 || c2 == c3)
cout << "There are 3 of a
kind. \n";
}
unsigned pairs(c0 == c1) + (c0 == c2) + (c0; c1)
switch (pairs) {
case 0:
cout << "Nothing!";
break;
case 1:
cout << "There are 4 of a
kind. \n";
break;
case 2:
cout << "There are 3 of a
kind. \n";
break;
default: die("ERROR");
}
}
bool die(const string & msg) {
cout << "Fatal error : " << msg <<
endl;
exit(EXIT_FAILURE);
}
your logic was wrong I corrected the logic, Please give thumbs up, thanks
code:
#include<iostream>
#include <cstdlib>
#include <string>
#include<cmath>
using namespace std;
bool die(const string & msg);
int main() {
unsigned c0, c1, c2, c3;
cout << "Please enter 4 cards in[1,13]: ";
cin >> c0;
if (!cin) die("Input Failure");
if (c0 < 1 || c0 > 13) die("Out Of Range");
cin >> c1;
if (!cin) die("Input Failure");
if (c1 < 1 || c1 > 13) die("Out Of Range");
cin >> c2;
if (!cin) die("Input Failure");
if (c2 < 1 || c2 > 13) die("Out Of Range");
cin >> c3;
if (!cin) die("Input Failure");
if (c3 < 1 || c3 > 13) die("Out Of Range");
cout << c0 << " " << c1 << " " <<
c2 << " " << c3 << endl;
unsigned pairs=((c0 == c1) + (c0 == c2) + (c0== c3))+((c1 == c0) +
(c1 == c2) + (c1== c3))+((c2 == c0) + (c2 == c1) + (c2== c3))+((c3
== c0) + (c3 == c1) + (c3== c2));
int c=ceil((double)pairs/4);
switch (c) {
case 0:
cout << "Nothing!";
break;
case 1:
cout << "There are 2 of a kind. \n";
break;
case 2:
cout << "There are 3 of a kind. \n";
break;
case 3:
cout << "There are 4 of a kind. \n";
break;
default: die("ERROR");
}
}
bool die(const string & msg) {
cout << "Fatal error : " << msg << endl;
exit(EXIT_FAILURE);
}
4-card poker Prompt the user, input 4 fixed point values, which can be input in any...
Can someone help me put the string removee the return to an outfile and fix?? prompt: CS 575 LabEx14: no e’s Let the user specify an input file and an output file (text files). Read the input file and write the output file; the output file should be the same as the input file, except that it has no e’s. For example, if the input file had the line. Streets meet in the deep. Then the output file would have...
c++, I am having trouble getting my program to compile, any help would be appreciated. #include <iostream> #include <string> #include <string.h> #include <fstream> #include <stdlib.h> using namespace std; struct record { char artist[50]; char title[50]; char year[50]; }; class CD { //private members declared private: string artist; //asks for string string title; // asks for string int yearReleased; //asks for integer //public members declared public: CD(); CD(string,string,int); void setArtist(string); void setTitle(string); void setYearReleased(int); string getArtist() const; string getTitle() const; int...
I keep getting errors and i am so confused can someone please help and show the input and output ive tried so many times cant seem to get it.
main.cpp
#include <iostream>
#include <vector>
#include <string>
#include "functions.h"
int main()
{
char option;
vector<movie> movies;
while (true)
{
printMenu();
cin >>
option;
cin.ignore();
switch (option)
{
case 'A':
{
string nm;
int year;
string genre;
cout << "Movie Name: ";
getline(cin, nm);
cout << "Year: ";
cin >> year;
cout << "Genre: ";
cin >> genre;
//call you addMovie() here
addMovie(nm, year, genre, &movies);
cout << "Added " << nm << " to the catalog"
<< endl;
break;
}
case 'R':
{
string mn;
cout << "Movie Name:";
getline(cin, mn);
bool found;
//call you removeMovie() here
found = removeMovie(mn, &movies);
if (found == false)
cout << "Cannot find " << mn << endl;
else
cout << "Removed " << mn << " from catalog"
<< endl;
break;
}
case 'O':
{
string mn;
cout << "Movie Name: ";
getline(cin, mn);
cout << endl;
//call you movieInfo function here
movieInfo(mn, movies);
break;
}
case 'C':
{
cout << "There are " << movies.size() << " movies
in the catalog" << endl;
// Call the printCatalog function here
printCatalog(movies);
break;
}
case 'F':
{
string inputFile;
bool isOpen;
cin >> inputFile;
cout << "Reading catalog info from " << inputFile
<< endl;
//call you readFromFile() in here
isOpen = readFile(inputFile, &movies);
if (isOpen == false)
cout << "File not found" << endl;...
pls help
2. Design a password generator that takes input from the user in the form of string and are integer. A string consists of four characters and a number consists of four integers obtained from the user. The following Figure 1 will explain how the password is generated. Print out the output for "asdf" and 1234. 14 12 13 C4 11 C2 C3 C1 Input 12 11 C1 13 4 C3 C2 C4 Re-arrange C2 C1 4 12 C3...
i have problem where the address is not save to my file after i input a new address and exit it #include<string> #include<iostream> #include<fstream> #include<sstream> using namespace std; typedef struct date { int day; int month; int year; }Date; typedef struct add { string building; string street; string city; string state; string zip; }Address; typedef struct entry { string firstName; string lastName; Address address; string phNo; Date...
In C++ please!
*Do not use any other library functions(like strlen) than the
one posted(<cstddef>) in the code below!*
/**
CS 150 C-Strings
Follow the instructions on your handout to complete the
requested function. You may not use ANY library functions
or include any headers, except for <cstddef> for
size_t.
*/
#include <cstddef> // size_t for sizes and indexes
///////////////// WRITE YOUR FUNCTION BELOW THIS LINE
///////////////////////
///////////////// WRITE YOUR FUNCTION ABOVE THIS LINE
///////////////////////
// These are OK after...
In this lab, you will need to implement the following functions
in Text ADT with C++ language(Not C#, Not Java
please!):
PS: The program I'm using is Visual Studio just to be aware of
the format. And I have provided all informations already! Please
finish step 1, 2, 3, 4. Code is the correct format of C++ code.
a. Constructors and operator =
b. Destructor
c. Text operations (length, subscript, clear)
1. Implement the aforementioned operations in the Text ADT...
Hello, I have some errors in my C++ code when I try to debug it.
I tried to follow the requirements stated below:
Code:
// Linked.h
#ifndef INTLINKEDQUEUE
#define INTLINKEDQUEUE
#include <iostream>
usingnamespace std;
class IntLinkedQueue
{
private: struct Node {
int data;
Node *next;
};
Node *front; // -> first item
Node *rear; // -> last item
Node *p; // traversal position
Node *pp ; // previous position
int size; // number of elements in the queue
public:
IntLinkedQueue();...
Can somebody help me with this coding the program allow 2 players play tic Tac Toe. however, mine does not take a turn. after player 1 input the tow and column the program eliminated. I want this program run until find a winner. also can somebody add function 1 player vs computer mode as well? Thanks! >>>>>>>>>>>>>Main program >>>>>>>>>>>>>>>>>>>>>>> #include "myheader.h" int main() { const int NUM_ROWS = 3; const int NUM_COLS = 3; // Variables bool again; bool won;...
C++ - I have a doubly linked list, but I haven't been able to get the "reverse list" option in the code to work(It's option #in the menu in the program). I received this guidance for testing: Test 4 cases by entering (in this order) c,a,z,k,l,m This tests empty list, head of list, end of list and middle of list. Then delete (in this order) a,z,l. This tests beginning, end and middle deletes. This exhaustively tests for pointer errors. #include...