Need help with app

Hello,

I need help to create a simple app where you need to insert the amount of players and their names. The players drops dice from 0 to 99 and the biggest score should be displayed.

The problem is that I am not allowed to use conditions, arrays described directly (except array of class objects) and string variables (char pointer allowed)

Thank you for the possible help
Hello mario883,

The problem is that I am not allowed to use conditions
.
Alright you have my interest. What do you mean by "condition" and what are you not allowed to use?

Whether this is a school assignment or something else it helps to include the full instructions.

Andy
Mario,

This usually works a lot better if you show us what you've tried first, and then we can help you with run-time/compile-time errors. But give it an attempt yourself first.

But as Andy mentioned, no "conditions" is really vague. Something as simple as a for loop is still testing a "condition" every loop. Do you just mean no "if" statements? Nothing against you, but this is quite the asinine requirement from your instructor.
Last edited on
Andy,

I think that means if and else statements. Unfortunately the instructions are in my native language, so I tried my best to translate it. :)

Ganado,

The point is that I'm noob in C++ programming language and I don't know where to start from. All I know is very basics of C++
Last edited on
it is NOT possible to determine who won without a condition, though you can hide the condition by using sort(), max(), or other such things that have the condition you need inside them. Are these tools allowed?

As you describe it, you are trying to solve this:
you have 10 numbers.
you cannot compare them against each other.
Which one is biggest?

*** actually, there may be a way to use bit-wise logic to jack the numbers together as they come in such that the largest one is the final bit twiddled result. This is not something a beginner could do, though. Or an unrolled bucket sort, perhaps... that would do it...
theres probably a cleaner way but a function pointer to a do-nothing function and a print answer function, called off a unrolled bucket sort, and the answer function does exit or terminate... that is the best I have off the top of my head.
eg
fptr[bucket[99]]; //so if the max is 99, it invokes the function pointer and terminates
fptr[bucket[98]]; //else it calls the do nothing one and then gets here... etc... all the way down 0 ...
fptr[bucket[97]];

Last edited on
There is a picture in the task that describes how it works:
How many players?
3
First player name:
John
Second player name:
Peter:
Third player name:
Tom

Then I think the app makes a random number for each player from 0 to 99 and displays it. And in the final it displays the winner whose number is biggest
Ok, but can you, or can you not, do boolean checks (x < y) or conditional statements (if (x <y) ) ? Its unclear what is not allowed: the problem statement itself is clear.
This site's tutorial: http://www.cplusplus.com/doc/tutorial/

It sounds like you can have arrays of classes? So do something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <cstdlib>
#include <ctime>

class Player {
  public:
    char name[100];
    int number;
};

int main()
{
    using namespace std;

    cout << "How many players? ";
    int num_players;
    cin >> num_players;
    cin.ignore(); // remove newline in buffer for future getline call

    Player* players = new Player[num_players];
    for (int i = 0; i < num_players; i++)
    {
        cout << "Player " << (i+1) << " name: ";
        cin.getline(players[i].name, 100);
    }
    delete [] players;
}


I've already shown too much. To generate random numbers, one would normally use modern <random> utilities, but since it sounds like your instructor wants you do do things the old way, you can use rand() % 100 to generate numbers from 0 to 99, inclusive.

Ask specific questions about what you don't understand if you want more help. I've already done too much of the assignment.
Last edited on
Ganado,

Thank you so much. You are my savior!
Topic archived. No new replies allowed.