C :: Bulls And Cows Program - Compare Table With Input String
Dec 14, 2013
I'm having a small problem on comparing a table i coded with a string that I want to input. I'm actually building a Bulls and Cows program and this is part of my assignment. What i want to do is to input a string and from the table get the results compared to the string i inputted.
Few words about the Bulls and Cows program.
The game involves two players, a coder and a cracker. The coder (either a person or a computer) chooses the four-digit number with all different digits and keeps it secret. The cracker tries to guess the secret number. After a guess, the coder gives you information about number of digits which were correctly guessed but in the wrong place (they are called 'cows') and how many are both the right digit and in the correct place (they are called 'bulls').
For example, if the coder chooses the secret number 0419 and the cracker guesses 6039, then the coder scores this as 1 cow, since 0 is a digit in the secret number that's in the wrong place, and 1 bull (9 is in the right place.)
what i want to do is when i input a string it scans the whole table of possibilities and gives me the results based on the string. so each row of my table is (let's say the secret code) and based on the given string(the guess) it gives me the result. Here's my table code:
Code:
void initialize(int poss[1296][4])
{
int i=0;
int j, k=0;
int m;
[Code] .....
View 2 Replies
ADVERTISEMENT
Nov 30, 2013
I am working on a String compare program and i got the program to work properly i was just wondering how to put user input into quotes.
here is my programming
int main {
const int LENGTH = 40;
char s1[LENGTH], s2[LENGTH];
cout << "== String Compare ==" << endl;
cout << "Enter a word" << endl;
[Code] ....
the input is :
Dorito
dorito
the output needs to look like this:
"Dorito" comes before "dorito".
View 2 Replies
View Related
Jul 14, 2014
I have problem with string compare. I want to compare the string user input with a string in binary. And I don't know how to do it. Problem in function login();Here is the code: And you also can download file in attachment too..
Code:
#include<conio.h>#include<dos.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
char nsb=1;
char ch, password[20], passlogin[20], inputpass[20], checked[20];
FILE *fp;
}
[code]....
View 1 Replies
View Related
Nov 27, 2014
Write a program to make a table for any input number and then continuesly ask to press y to print more table and if you press any key other than y then program must be terminate using while loop and do while loop. How to start or end with it.
View 2 Replies
View Related
Jan 25, 2013
If a user enters a string of boolean algebra it will ouput the table.
I have input parsing, cycling through the combinations, and outputing working. However once i parse the input I am not sure what to do with it. I have thought of having it write the parsed input to a new file as a function and then use that function, but that seems bad.
How to dynamically create the function, how to implement it.
BTW This is a console function, if that changes anything.
View 2 Replies
View Related
Nov 19, 2013
I am having an issue with my sort function. This is one part of the Hash table program. The main issue is that I am trying to sort the pointer table after all of the values have been entered. The ptr_sort function is not a class function and so I am therefore unable to use the class variables psize and pTable. Is there another way I should be trying this? it is a Vector should I use the sort() function from the vector class in STL?
#include "/home/onyuksel/courses/340/progs/13f/p9/util9.h"
#include "/home/onyuksel/courses/340/progs/13f/p9/hTable.h"
#ifndef H_TABLE1
#define H_TABLE1
void ptr_sort ( );
[Code] ....
View 1 Replies
View Related
Mar 20, 2014
My program works before i declare a new variable in class. Right after i declared a new int variable called prevans in my guess class, my program crashes when it runs.
Here's my code: Code: #include <iostream>
#include <time.h>
#include <cstring>
#include <cstdlib>
#include <vector>
[Code].....
View 14 Replies
View Related
Jan 11, 2015
Program is about to compare any two numbers input. Then, it will display whether the number is minimum or maximum. Use switch statement.
#include <iostream>
using namespace std;
void main() {
int num1, num2;
cout << "Input 2 integers separated by a space. " << endl;
cin >> num1 >> num2;
[Code] .....
View 4 Replies
View Related
Feb 23, 2015
So we have a weekend assignment that is "Write a c++ program that will allow a user to input their first name into a string, and use the switch/case statement to produce the following output. Your Program should prompt the use rwith the numbers and the options for each (school, classification, and mood) allowing them to make a choice"
My issue is with the output. The output at the end is the number that they input and not the name of the case they chose, so if they chose option 1 for school it does not print out "BRCC" at the end for the output it prints a 1.
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string name;
cout << "Please enter your name: ";
cin >> name;
[code].....
View 7 Replies
View Related
Nov 3, 2014
Explain this program to reverse an input string:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main() {
void reverse(void);
clrscr();
reverse();
[Code] ....
Do not assume i know about getchar and putchar.
View 2 Replies
View Related
Nov 3, 2014
What do I put to have UserNumber == 1-10? In other words I want it to say...
if UserNumber equals 1 through 10 <<<<This is where I'm having the issue.
Do this
Else
Do this
namespace ConsoleApplication1 {
class Program {
static void Main(string[] args) {
Start:
Console.WriteLine("Please enter a number between 1 and 10");
int UserNumber = int.Parse(Console.ReadLine());
[Code]...
I got it.
View 8 Replies
View Related
Mar 17, 2015
I am trying to generate possible combinations of 4 lower case letters from aaaa - zzzz. The words will then be used against a file that contains encrypted passwords that each relate to a 4 lower case word. I have successfully generated the words. Now all i need to do is put the created words (aaaa, aaab, etc...) to an array so I can use crypt((array[i+1]), buff) and print the encrypted 4 letters that come from the file. I am having a lot of trouble complete this though.
New problems that are occurring
The main problem is in the all function and main. I'm not wanting to print the aaaa, aaab, aaac, etc to the screen but I want to put it in an char array so that i can compare each individually to each line from the file using crypt. How to put all 456976 combinations into an array, compare it to each line of code, and print the solutions to the screen.
File:
$1$6gMKIopE$I.zkP2EvrXHDmApzYoV.B.
$1$pkMKIcvE$WQfqzTNmcQr7fqsNq7K2p0
$1$0lMKIuvE$7mOnlu6RZ/cUFRBidK7PK.
Code:
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
[Code]....
View 1 Replies
View Related
Sep 21, 2014
This program will allow the user to input string then scans the file if it contains the same string given by the user. But i always get "MATCHED" even if i enter random string. I tried and tried to place the if statement in different positions but i dont get my expected output.
Code:
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#include<string.h>
int main() {
int found;
[Code] ....
View 6 Replies
View Related
Feb 25, 2015
i'm trying to compare a string to a certain string in an array, my code is as follows:
#include <iostream>
using namespace std;
int tu;
int nu=0;
[Code].....
View 5 Replies
View Related
Apr 23, 2014
I'm trying to write a program that uses the Boost library to input a string date in the format mm/dd/year and outputs to the string its corresponding day of the week. I wrote the program that I thought would accomplish this, but it doesn't seem to work. Below is the code I wrote:
#include <string>
#include <iostream>
#include "boost/date_time/gregorian/gregorian.hpp"
[Code]....
When I compile this using codeblocks it gives me the error "In function `ZN5boost9date_time19month_str_to_ushortINS_9gregorian10greg_monthEEEtRKSs':|
C:Users
osaDesktop est3........Liboost_1_55_0oostdate_timedate_parsing.hpp|67|undefined reference to `boost::gregorian::greg_month::get_month_map_ptr()'". And it takes me to the file date_parsing.hpp and highlights line 67. I don't understand why this isn't working.
View 3 Replies
View Related
Oct 31, 2014
I am trying to get a list of queries to work right now. I have it so that the user will input 1 of 5 things to compare twin primes in a list. I am just trying to get the queries working fully before actually determining the twin primes that need to be output. The console input will be something like "<= 61" and will display all twin primes from 3 to 61, inclusive.
Well, I thought I had it 100%... Then I realized I have a problem, though. So, I'm reading the string in until a space so I can read in the number after that. So that works fine, but then I also want the "all" and "random" console inputs to work, but they won't unless I put a space after them, which is what I'm trying to avoid...
So, I tried just simply asking for another console input after all of my if statements for the string compare after the first console input. That obviously doesn't work either, though, because it still only wants the first "getline" where it reads until the whitespace.
How to be able to do both on the same console input... The relevant code is posted below:
cout << endl << "What do you want to know about your list of twin primes?" << endl;
string qprompt1;
string qprompt2;
getline(cin, qprompt1, ' ');
string comp1 = ">";
string comp2 = ">=";
[Code] .....
View 5 Replies
View Related
Feb 20, 2014
I have made a program that converts or reverses an input string. Here is my code working fine
static void Main(string[] args){
string input = Console.ReadLine();
string[] words = input.Split(' ')
for (int i = words.Length; i > 0; i--)
Console.Write(words[i - 1] + " ");
Console.WriteLine();
Console.ReadLine();
}
How can I write this program in pseudo code?
View 2 Replies
View Related
Mar 20, 2013
I have this code :
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
[Code] ...
And this error occued with me I don't know why ???
myHeader.h:42:19: error: expected ")" before string constant
This code is compiled from file called myHeader.h ...
View 2 Replies
View Related
Mar 5, 2014
I'm trying to read a string and then compare it to a word.
My code:
char* cmd = "start";
std::cin >> cmd;
if (strcmp (cmd, "eval"))
eval ();
When the program gets to the cin part, it breaks.
View 4 Replies
View Related
May 9, 2014
I would like to compare two strings, one of which is an independently stored string - the other being a string within a vector. However, i do not know how to do this, as
string thisString = "yes";
vector<string> stringHere;
stringHere.push_back("no");
if (thisString == stringHere[0]) {
cout << "It worked." << endll;
}
does not appear to work.
View 2 Replies
View Related
Apr 19, 2013
I have a list of objects that I need to read information from each object to compare to a user input prompt.
#include "Passenger.h"
#include "Reservation.h"
#include "Aircraft.h"
#include <iostream>
#include <fstream>
#include <string>
#include <list>
using namespace std;
//Function Prototypes
void flightRoster(list<Reservation>&);
[Code] ....
View 1 Replies
View Related
May 5, 2014
I am trying to compare a string that i have entered with a set of strings that have already been stored in a file. I am using strcmp function but i am not getting the result.
Code:
printf("
Enter string:");
scanf("%s",&m);
ptr_file =fopen("abc.text","r");
[Code] .....
View 10 Replies
View Related
Jan 28, 2013
Ok, I'm having a few problems with strings, mostly string functions saying they're not able to compare a string with a char pointer.
int main()
{
int counter = 0;
int x, y, z;
[Code].....
My goal is to take in a command and store it in a string. Different commands have different amounts of information I need. One command is "new flight <flightnumber> <seats available>". First, I try to understand which command is being asked, using the first character to decide. Once I can assume which command is being attempted, I try to separate the string into smaller strings (words) using strtok. I then compare the words that should be constant (new and flight), to make sure the command is syntactically correct (which I use strcmp for). Then I'll go on to create a new flight, which is a class that takes in a char * and integer (which is why I need to convert a char * to integer).
View 2 Replies
View Related
Jun 26, 2014
How do I compare a string vector against an enumerated type? My code so far is:
void convertToLastFirst(vector<string>&names){
enum NameFormat{FIRST, LAST};
for (size_t i = 0; i < names.size(); i ++){
if (names[i] FIRST){
names[i] = LAST;
}
}
}
View 1 Replies
View Related
Oct 26, 2013
I would like to print a multiplication table, with the dimension n given as input. I attached how the table looks like for n=7.
How do you output the character "-" in that sequence? The first and last numbers have 13 "-" characters before and after them, but the numbers in between have 8 "-" characters.
View 2 Replies
View Related
Feb 18, 2013
Modify your code by adding your own tests to see if your functions work right. Include at least 6 separate tests, of your choosing.
For example, test the compare function with the first parameter as a blank string -- then with the 2nd as a blank -- then both. Test compare with the first string shorter than the second -- then the other way around. Test your copy function with long strings.
I am struggling with how to use the compare function with a parameter as a blank string. I tried leaving the first parameter blank but doing ("",text) but I don't think that is the correct way of doing this.
#include <cstring>
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int myStrLen(const char[]); // return length of null-terminated string stored in char array
[Code] ....
View 2 Replies
View Related