struggling with c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

struggling with c++

how do i store data from a text file into a 2d array? i also need to specifically select all rows where column 1 =s 1 if that makes sense? i have what will be 4 columns wide and 33 rows. like this 1 Dwarf 2 4 11 Armour 1 6 Wall 0 5 10 Sword 2 4 Bless 2 2 1 Cannon 4 1 1 Dwarf 2 4 1 Cannon 4 1 2 Fireball 3 1 Cannon 4 1 8 Elephant 4 4 1 Swordswinger 2 2 4 Bless 2 2

7th Apr 2018, 2:27 PM
Matthew Gibson-storey
Matthew Gibson-storey - avatar
3 Answers
+ 1
This way you have 3 groups of 33 strings. Is that what you want?
7th Apr 2018, 4:50 PM
Timon Paßlick
0
this is my brief. • You may implement a simplified version of the assignment to obtain a bare pass mark of 40%. If you follow this route then you cannot gain more than a pass mark of 40%. • There are two players: “Sorceress” and” Wizard”. • The game is played in rounds. • The game has a maximum of 30 rounds. In each round each player takes a turn. “Sorceress” begins each round of the game. • The players have health. Each player begins the game with 30 health points. When a player is attacked they lose health. When the health of a player reaches 0 they lose the game. • Each player has a deck of cards. The deck of cards is read from file at the beginning of the game. Each player has their own deck: "sorceress.txt" and "wizard.txt". You may implement the decks as global variables. • Go through deck in order, each player playing the next card in the deck. (Note that this will mean that the cards will always come out in the same sequence.) • Cards attack the enemy player. • The game ends at the end of the round when a player has 0 or less health. • Use an array to store the cards. You do not need to use pointers or dynamic memory allocation. • Comment your code but no need to comment each function. • Only use card type 1.
7th Apr 2018, 2:27 PM
Matthew Gibson-storey
Matthew Gibson-storey - avatar
0
this is my code so far #include "stdafx.h" #include<iostream> #include<string> #include<fstream> using namespace std; int main() { ifstream file("sorceress.txt"); if (file.is_open()) { string sorDeck[3][33]; for (int x = 0; x <3 ; ++x) { for (int y = 0; y<33; y++) { file >> sorDeck[x][y]; cout << sorDeck; cout << endl; } system("pause"); } return (0); } }
7th Apr 2018, 2:28 PM
Matthew Gibson-storey
Matthew Gibson-storey - avatar