#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string getRandWord();
void checkLetter(char&, string&, int&,
string&);
int main() {
string RandomWord = getRandWord();
string hiddenWord = "";
unsigned long int _length_ = RandomWord.length();
int chances = int(_length_)+1;
char newLetter;
hiddenWord.append((_length_),'_');
cout << "The Word is "<< _length_ <<" letters long." << endl;
while(chances > 0){
cin >> newLetter;
checkLetter(newLetter, RandomWord, chances, hiddenWord);
if(hiddenWord == RandomWord){
cout << "Congratulations! You won the game." <<
endl;
break;
}
chances--;
}
return 0;
}
void checkLetter(char &newLetter, string &randstr, int
&strlen, string &hiddenWord){
string::iterator it;
for(auto it = randstr.begin(); it != randstr.end();++it){
if(*it == newLetter){
hiddenWord.at(it - randstr.begin()) = newLetter;
}
}
cout << hiddenWord << endl;
}
string getRandWord(){
string filePath = "/Users/nedimkanat/XCODE/testcpp/testcpp/";
enum sizes {
COUNTER = 0,
ARRAY_SIZE = 5
};
srand((unsigned)time(NULL));
int randint = rand() % ARRAY_SIZE;
string str;
vector<string> arr;
ifstream file(filePath+"words.txt");
int counter = COUNTER;
if (file.is_open()){
while (getline(file,str) && counter < ARRAY_SIZE){
arr.push_back(str);
counter++;
}
file.close();
} else {
cout << "File is not open" << endl;
}
if(arr.empty()){
cout << "CANCER" << endl;
}
return arr.at(randint);
}
This program is part 1 of a larger program. Eventually, it will be a complete Flashcard...
Please help and follow instructions, c++ , let me know if there is any questions Description: This program is part 1 of a larger program. Eventually, it will be a complete Flashcard game. For this part, the program will Prompt the user for a file that contains the questions – use getline(cin, fname) instead of cin >> fname to read the file name from the user. This will keep you in sync with the user’s input for later in the...
Help c++ Description: This program is part 1 of a larger program. Eventually, it will be a complete Hangman game. For this part, the program will Prompt the user for a game number, Read a specific word from a file, Loop through and display each stage of the hangman character I recommend using a counter while loop and letting the counter be the number of wrong guesses. This will help you prepare for next week Print the final messages of...
Program In Assembly For this part, your MAL program must be in a file named p5b.mal. It must have at least one function in addition to the main program. For the purposes of Part (b), you may assume the following 1. Any line of text typed by a user has at most 80 characters including the newline character. 2. A whitespace character refers to a space, a tab or the new line character. 3. A word is any sequence of...
This program will make Maze game. Please Help in c++ Prompt the user for a file that contains the maze. Read it into a two-dimensional array Remember you can use inputStream.get(c) to read the next character from the inputStream. This will read whitespace and non-whitespace characters Don’t forget to read the newline character at the end of each line Print the maze to the screen from your array You should include a ‘*’ in your maze to indicate where the...
please I need help with the question: Problem: Write a C++ program that reads each character from a user input, extracts the character if it is a digit, and calculates the sum of all the digits. The program stops reading the user input when the new line character ‘\n’ is encountered. For the output of the program, you should print each digit extracted from the user input and the sum of all the digits. (*The main difference between “cin >>...
Below is the picture for the direction of my program and also the part where I have problems with I've already finished it and my code works correctly. But what I need to do is to "read the file name from the command line arguments" instead of the standard input (cin) that I did for step 1. I'm not sure how to do that. 2.13 PROGRAM 1: Calculating Coefficient Of Lift For this PROGRAM you will calculate the coefficient of...
Instructions Basically, you will modify the mathq program to make it satisfy a different set of requirements, and fix what is not working in it. Specifically, imagine that the client for whom we created the mathq program for would now like some changes. To be exact: Part 1: They want it to provide addition and subtraction problems as well as multiplication and division. They still want the choice to be random, as before, but now the problem is randomly multiplication,...
Java Programming Part 1 File encryption is the science of writing the contents of a file in a secret code. Your encryption program should work like a filter, reading the contents of one file, modifying the data into a code, and then writing the coded contents out to a second file. The second file will be a version of the first file, but written in a secret code. Although there are complex encryption techniques, you should come up with a...
C++ (1) Write a program to prompt the user for an input and output file name. The program should check for errors in opening the files, and print the name of any file which has an error, and exit if an error occurs. For example, (user input shown in caps in first line, and in second case, trying to write to a folder which you may not have write authority in) Enter input filename: DOESNOTEXIST.T Error opening input file: DOESNOTEXIST.T...
In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...