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)
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.
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]];
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.
#include <iostream>
#include <cstdlib>
#include <ctime>
class Player {
public:
char name[100];
int number;
};
int main()
{
usingnamespace 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.