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
3 Réponses
+ 1
This way you have 3 groups of 33 strings.
Is that what you want?
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.
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);
}
}