Member Avatar for Member #1227892

I need to do c++ programming without using array and function.please help me.i attach file below.

Dani AI

Generated

asked for a C++ Beyblade trading-card program under the constraint of “no arrays, no functions.” ’s suggestion to “hack at it using nothing but variables” is the simplest route, but it quickly becomes hard to read and maintain. The pragmatic middle ground is: keep all logic inline (no helper functions), avoid C-style arrays, and use tiny POD data records to group card attributes so the code remains understandable for a grader.

Use a plain struct (no methods) to hold each card’s fields, then give each slot an explicit, named variable (for example p1_card1, p1_card2, p2_card1, ...). Implement draws, comparisons and state changes with plain if/else or switch inside main. That stays inside the stated limits while keeping related data together and making the program easier to reason about than dozens of loose variables.

Example pattern (no arrays, no extra functions):

#include <iostream>
#include <string>

struct Card {
  std::string name;
  int attack;
  int defense;
  int stamina;
};

int main() {
  Card p1_card1 = {"Drift", 10, 5, 20};
  Card p2_card1 = {"Vortex", 8, 7, 18};

  int damage = p1_card1.attack - p2_card1.defense;
  if (damage > 0) p2_card1.stamina -= damage;

  std::cout << p1_card1.name << " vs " << p2_card1.name << " -> "
            << p2_card1.name << " stamina: " << p2_card1.stamina << '\n';
  return 0;
}

Troubleshooting and notes: print intermediate stats to verify calculations, test one clash at a time, and keep the number of fixed slots small. This approach is intentionally verbose and brittle for large collections; if the project grows, present a refactored version using arrays/vectors and helper functions to the instructor to show maintainability benefits. This keeps the spirit of ’s “variables-only” idea but makes the code easier to grade and debug.

Recommended Answers

All 3 Replies

  1. "You did not copy your friends’ codes and you do not let them copy your codes."
  2. I see no mention we can't use arrays or functions.

Since no one here can give you code, let's hear where you are stuck along with my question which is why can't we use arrays and functions.

commented: I don't learn array yet..my lecturer doesn't teach me yet that why i cannot use it +0

Then hack at it using nothing but variables. remember that I can't supply you code according to the assignment. This will look terrible and is a very bad way to learn coding IMO. Frankly if it was my assignment I would code it with what I know and challenge the prof that learning this is teaching bad programming habits.

commented: You know what they say. Malpractice makes malperfect. +15

I need to make this game too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.