Help coding UNO

So I have an assignment that requires me to code UNO from the ground up, although not all rules need to be implemented just yet.
I understand that I need counters for the cards but I keep going in circles with the card implementation.

If anybody could help me start it out, I would be so grateful!
Hi Metro, I'd love to help, but you're going to need to help me:

1.) What is UNO? What are the rules you need?

2.) What code have you come up with so far?


With the information given so far, the only advice I could give you is to consolidate the card information into a class like so:

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
28
29
30
31
32
33
34
35
36
class Card
{
private:
	char type; // From a standard deck of cards, this will be Spades, Hearts etc
	int value; // From a standard deck of cards, this will be 4, 5, or King(13)
public:
	Card(char t, char v): type(t), value(v) {}
	const char& GetType() { return type; } 
	const int& GetValue() { return value; }
}

class Deck
{
private:
	std::vector<Card> cards;
public:
	Deck()
	{
		// Create cards and put in deck
		cards.push_back(Card('S',1)); // Ace of Spades
		// ...
		cards.push_back(Card('S',13)) // King of Spades
	}
	void Shuffle() {} // Implement a card shuffle algorithm here
	const Card& Draw() { return cards[std::rand() % cards.size()]; } // Get a random card
}

int main()
{
	Deck deck_of_cards;
	deck_of_cards.Shuffle();
	Card player_1 = deck_of_cards.Draw();
	Card player_2 = deck_of_cards.Draw();
	if(player_1.GetValue() > player_2.GetValue()) std::cout << "Player 1 has higher card!\n";
	else std::cout << "Player 2 has higher card!\n";
}
Hey Megatron,

So UNO is a card game that consists of 4 colors(blue, green, red, yellow), and each color has 2 cards of each number 0-9, with 2x skips (for skip turns), 2x +2 cards(to add 2+ to your player hand), and 2x switch direction cards(for switching direction of rotation amongst higher amounts of players, past 2).

The objective is to get the least amount of cards, by either matching the card on the "table" with the same color or number, if no matches you get 2 additional cards to your handdeck.
There are additional cards called wild cards, which V1 are not required to match, but to reset the "table" deck to any color, and number the player chooses, and V2 is same as V1, yet the opponent or next player picks up 4+ cards.

From what I need to code for the project is;
1. two players; one human, on ai/cpu
2. cards(possibly all 4 colors, if not 2 or 3 is fine), 0-9, and +2 type, with both V1 and V2 wilds
3. hopefully working to some extend, although arrays and classes cannot be used


Currently, I need help with generation the cards, possibly out to a file, so I could read them back in for points in that section.
Part of this code came from a project we did as a class: rock, paper, scissors, which worked for 3 char, yet a 4th isn't working nor the letter changes, maybe its due to ASCII numbering?

So far I have:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
char cardclr;//Card color [red, green, blue, yellow]
          int cardnum, //Card number [0-9]
               wild, //Wild card, gives choice for any card in game
               wildP4, //Same as wild, yet with a +4 to opponent
               blueP2, //Blue card, with +2 for opponent
               redP2, //red card, with +2 for opponent
               grnP2, //green card, with +2 for opponent
               yllwP2,//yellow card, with +2 for opponent
               plyr1Dk,//player 1 deck
               plyr2Dk,//player 2 deck
               plyr3Dk,//player 3 deck
               plyr4Dk;//player 4 deck

    cardclr=rand()%3+'G';
    cardclr=cardclr>'B'?'R':cardclr;
   //cardclr=cardclr>'G'?'R':cardclr; 
Last edited on
although arrays and classes cannot be used


Well that sucks and throws the best way of doing this out of the window. :-)

Though I am curious:

The objective is to get the least amount of cards, by either matching the card on the "table" with the same color or number, if no matches you get 2 additional cards to your handdeck.


The "you get 2 additional cards" part makes me believe the table has a deck people pick from, but if you can't use an array, how are you expected to hold 100+ cards without a container of sorts?

You could easily enough design cards to be a number. We could declare an enum of colour offsets to determine what number range is what card:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
enum ColourIndex { BLUE = 0, RED = 40, GREEN = 80, YELLOW = 120 };
enum CardIndex { C0 = 0, C1, C2, C3, C4, C5, C6, C7, C8, C9, CX1, CX2, CX3, CX4, CX5, CX6, CX7, CX8, CX9, CSKP, CXSKP, CP2, CXP2, CSWTCH, CXSWTCH }; // Is V1 and V2 also part of the colour cards, or separate?
/*
B0 = 0	B1 = 1 	B2 = 2 	B3 = 3
B4 = 4 	B5 = 5 	B6 = 6 	B7 = 7
B8 = 8 	B9 = 9
2B0 = 10 	2B1 = 11 	2B2 = 12
2B3 = 13 	2B4 = 14 	2B5 = 15
2B6 = 16 	2B7 = 17 	2B8 = 18
2B9 = 19
BSKP = 20 	2BSKP = 21
BP2 = 22 	2BP2 = 23
BSWTCH = 24 	2BSWTCH = 25

R0 = 40
...
2R9 = 59
...
*/

int card = ColourIndex::BLUE + CardIndex::CSKP;


The other thing that worries me about your limitation on arrays is how you are going to pick up cards to a hand deck. You can't use a single integer to store multiple. You didn't mention a card limit the player can have so declaring a set number of integers is also out the window.

You're not expected to define some kind of bitfield are you? Using the bits of a type as a single flag. It's possible to use the bits of 4 integers to track all the cards that are taken out of the deck or put back in, but very bloody tedious and stupid to do for this task. Stuff like that is usually used in chess engines to map where pieces are on a board.

Making a deck of cards without being able to group in a class or struct and list with an array is a task in itself, maybe I am missing something?

possibly out to a file, so I could read them back in for points in that section


You could write the numbers out to a file, and read them back:

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Write a new card deck to file
void WriteDeck(std::string filename)
{
	std::ofstream ofs(filename)
	if(!ofs)
	{
		std::cout << "Could not open filestream.\n";
		return;
	}
	for(int colour = 0; colour < ColourIndex::Yellow + 1; colour += 40)
	{
		for(int card = 0; card < CardIndex::CXSWTCH+1; card++)
		{
			ofs << colour+card << "\n";
		}
	}
}

std::ifstream deck_file;
bool init = false;

bool IfExists(std::string filename)
{
	std::ifstream ifs(filename);
	if(ifs) return true;
	return false;
}

bool InitDeckFile(std::string filename)
{
	deck_file.open(filename);
	if(!deck_file)
	{
		std::cout << "Could not open " filename << ".\n";
		return false;
	}
	init = true;
	return true;
}

int GetNextCardFromDeck()
{
	if(!init) return -1; // ifstream not open
	if(ifs)
	{
		int card;
		if(ifs >> card) return card;
		return -2; // File error / end of stream perhaps
	}
        return -1; // Stream bad
}

int main()
{
	if(!IfExists("Deck.txt")) WriteDeck("Deck.txt");
	if(!InitDeckFile("Deck.txt")) return 1;
	int player_card_1 = GetNextCardFromDeck();
	int player_card_2 = GetNextCardFromDeck();
}


Holding multiple cards in a players hand to use will be difficult, is there a max hold limit or you can't use vectors? A bit field approach is pretty darn overkill and I have no other ideas at the moment.

Hope this helps.

EDIT: Would this be considered cheating an array?

1
2
3
4
5
6
7
8
9
int* deck_ptr;
deck_ptr = std::malloc(sizeof(int)*100); // Allocate 100 int's worth of memory
int* current_deck_card = deck_ptr; // Make a second pointer so we don't loose position
for(...)
{
        current_deck_card* = some_int;
        current_deck_card++; // Increase pointer location to next free address
}
std::free(deck_ptr); // When we are finished with the memory, release it 
Last edited on
Yeah, the arrays and classes are project 2, next week, yet this one is huge.

The professor hinted on my project using counters, specifically 4 of them. The whole game doesn't need to be implemented 100% exact, which I may forget the +2/+4 cards, skips, and switch direction, untill project 2, which is coming up soon. Also Project 2 will allow arrays and classes, with no limitations.

But for now, I do like your idea
You could easily enough design cards to be a number.


I found this, yet I kind of believe your idea is better: https://www.daniweb.com/programming/software-development/threads/477707/c-uno-game-help

Its similar from what I started with yet, better for cards and not comparisons.
I was trying to rand generate RGBY, and rand 0-9 but its not ideal in this situation
Initially, I was comparing everything to these examples:
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream> //I/O Library -> cout,endl
#include <fstream>  //File Library
#include <cstdlib>  //exit()
using namespace std;//namespace I/O stream library created

//User Libraries

//Global Constants
//Math, Physics, Science, Conversions, 2-D Array Columns

//Function Prototypes

//Execution Begins Here!
int main(int argc, char** argv) {
    //Declare Variables
    ofstream out;

    //Initial Variables
    out.open("Clock.out");
    
    //Map/Process Inputs to Outputs
    for(char ampm='0';ampm<='1';ampm++){
        for(int hours=0;hours<=12;hours++){
            for(char mins10='0';mins10<='5';mins10++){
                for(char mins='0';mins<='9';mins++){
                    for(char sec10='0';sec10<='5';sec10++){
                        for(char sec='0';sec<='9';sec++){
                            if(ampm=='1'&&hours==12){
                                out<<"00:00:00 AM"<<endl;
                                exit(EXIT_SUCCESS);
                            }
                            if(hours<10)out<<'0'<<hours<<':'
                                    <<mins10<<mins<<':'
                                    <<sec10<<sec
                                    <<" "<<(ampm=='0'&&hours<12?"AM":"PM")<<endl;
                            else out<<hours<<':'
                                    <<mins10<<mins<<':'
                                    <<sec10<<sec
                                    <<" "<<(ampm=='0'&&hours<12?"AM":"PM")<<endl;
                        }
                    }
                }
            }
        }
    }

    //Close file
    out.close();



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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main(int argc, char** argv) {
    //Set the random number seed
    srand(static_cast<unsigned int>(time(0)));
    
    //Declare Variables
    char plyr1,plyr2;
    
    //Initialize Variables
    plyr1=rand()%3+'R'; //RST
    plyr1=plyr1>'S'?'P':plyr1;//PRS
    plyr2=rand()%3+'R'; //RST
    plyr2=plyr2>'S'?'P':plyr2;//PRS
  
    //Players choice
    cout<<"Rock Paper Scissors Game"<<endl;
    cout<<"Player 1 = "<<plyr1<<endl;
    cout<<"Player 2 = "<<plyr2<<endl;
    
    //Determine the winner
    if(plyr1==plyr2){
        cout<<"The game is a tie"<<endl;
    }else if(plyr1=='P'){
        if(plyr2=='S'){
            cout<<"Player 2 wins"<<endl;
        }else{
            cout<<"Player 1 wins"<<endl;
        }
    }else if(plyr1=='S'){
        if(plyr2=='R'){
            cout<<"Player 2 wins"<<endl;
        }else{
            cout<<"Player 1 wins"<<endl;
        }
    }else{
        if(plyr2=='P'){
            cout<<"Player 2 wins"<<endl;
        }else{
            cout<<"Player 1 wins"<<endl;
        }
    }



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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <iomanip>

using namespace std;

//User Libraries

//Global Constants - Math/Physics Constants, Conversions,
//                   2-D Array Dimensions

//Function Prototypes

//Execution Begins Here
int main(int argc, char** argv) {
    //Declare Variables
    int bdayday, bdaymon;
    //Initialize Variables
    
    //Process/Map inputs to outputs
    cout<<"This program will determine your horoscope sign from your birthday!"<<endl;
    do{
        cout<<"Type the month of your birthday using 1-12"<<endl;
        cin>>setw(2)>>bdaymon;
    }while(bdaymon<1||bdaymon>12);//Birthday Input (Month)
        if(bdaymon==1, 3, 5, 7, 8, 10, 12)//Incomplete Day limit for months
            {do{
                cout<<"Now type the day of your birthday"<<endl;
                cin>>setw(2)>>bdayday;
            }while(bdayday<1||bdayday>31);}//Birthday Input (Day)
    if((bdaymon==1&&bdayday>= 20)||(bdaymon==2&&bdayday<=18))//Begining of Range Parameters for horoscope signs
            {cout<<"Your horoscope sign is Aquarius"<<endl;}
        else if((bdaymon==2&&bdayday>=19)||(bdaymon==3&&bdayday<=20))
            {cout<<"Your horoscope sign is Pisces"<<endl;}
        else if((bdaymon==3&&bdayday>=21)||(bdaymon==4&&bdayday<=19))
            {cout<<"Your horoscope sign is Aries"<<endl;}
        else if((bdaymon==4&&bdayday>=20)||(bdaymon==5&&bdayday<=20))
            {cout<<"Your horoscope sign is Taurus"<<endl;}
        else if((bdaymon==5&&bdayday>=21)||(bdaymon==6&&bdayday<=20))
            {cout<<"Your horoscope sign is Gemini"<<endl;}
        else if((bdaymon==6&&bdayday>=21)||(bdaymon==7&&bdayday<=22))
            {cout<<"Your horoscope sign is Cancer"<<endl;}
        else if((bdaymon==7&&bdayday<=23)||(bdaymon==8&&bdayday<=22))
            {cout<<"Your horoscope sign is Leo"<<endl;}
        else if((bdaymon==8&&bdayday>=23)||( bdaymon==9&&bdayday<=22))
            {cout<<"Your horoscope sign is Virgo"<<endl;}
        else if((bdaymon==9&&bdayday>=23)||(bdaymon==10&&bdayday<=22))
            {cout<<"Your horoscope sign is Libra"<<endl;}
        else if((bdaymon==10&&bdayday>=23)||(bdaymon==11&&bdayday<=21))
            {cout<<"Your horoscope sign is Scorpio"<<endl;}
        else if((bdaymon==11&&bdayday>=22)||(bdaymon==12&&bdayday<=21))
            {cout<<"Your horoscope sign is Sagittarius"<<endl;}
        else if((bdaymon==12&&bdayday>=22)||(bdaymon==1&&bdayday<=19))
            {cout<<"Your horoscope sign is Capricorn"<<endl;}  //End of Range
        else {cout<<"Invalid Birthday Input"<<endl;} //Invalid range if ever meet
return 0;


Vectors are not allowed yet, due to the fact we haven't learned them yet, same for arrays and classes. Apologize, that shouldv'e been info in the beginning.
I currently am trying out your "fake array" and "file in/out." Trying to figure out how to implement it.
Hi again,

The professor hinted on my project using counters, specifically 4 of them.


Did this professor say what these counters should count?

The file read/write functions I previously gave should be in working order (Though I didn't compile so let me know) and the colour offset coding should also be fully implemented. Out of curiosity, in this UNO game, do you have to use the last received card you get? Or do you get to choose a card to place from you're hand? If you don't get to choose and have to place you're next available card, a counter could be used to count how many cards in the players hand, here's a near complete example:

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
enum ColourIndex { BLUE = 0, RED = 40, GREEN = 80, YELLOW = 120 };
enum CardIndex { C0 = 0, C1, C2, C3, C4, C5, C6, C7, C8, C9, CX1, CX2, CX3, CX4, CX5, CX6, CX7, CX8, CX9, CSKP, CXSKP, CP2, CXP2, CSWTCH, CXSWTCH, CARD_COUNT };

// Write a new card deck to file
void WriteDeck(std::string filename)
{
	std::ofstream ofs(filename)
	if(!ofs)
	{
		std::cout << "Could not open filestream.\n";
		return;
	}
	for(int colour = 0; colour < ColourIndex::Yellow + 1; colour += 40)
	{
		for(int card = 0; card < CardIndex::CXSWTCH+1; card++)
		{
			ofs << colour+card << "\n";
		}
	}
}

std::ifstream deck_file;
bool init = false;

bool IfExists(std::string filename)
{
	std::ifstream ifs(filename);
	if(ifs) return true;
	return false;
}

bool InitDeckFile(std::string filename)
{
	deck_file.open(filename);
	if(!deck_file)
	{
		std::cout << "Could not open " filename << ".\n";
		return false;
	}
	init = true;
	return true;
}

int GetNextCardFromDeck()
{
	if(!init) return -1; // ifstream not open
	if(ifs)
	{
		int card;
		if(ifs >> card) return card;
		return -2; // File error / end of stream perhaps
	}
        return -1; // Stream bad
}

// Check if player card and table card is of same colour
bool ValidColour(int pcard, int tcard)
{
	if(pcard < ColourIndex::RED-5 && tcard < ColourIndex::RED-5) return 1; // Both player card and table card is BLUE(<35), valid move
	if(pcard < ColourIndex::GREEN-5 && tcard < ColourIndex::GREEN-5)
		if(pcard >= ColourIndex::RED && tcard >= ColourIndex::RED) return 1; // Both cards are RED(Between 40-74)
	if(pcard < ColourIndex::YELLOW-5 && tcard < ColourIndex::YELLOW-5)
		if(pcard >= ColourIndex::GREEN && tcard >= ColourIndex::GREEN) return 1; // Both cards are GREEN
	if(pcard >= ColourIndex::YELLOW && tcard >= ColourIndex::YELLOW)
		if(pcard < ColourIndex::YELLOW + CardIndex::Card_Count && tcard < ColourIndex::YELLOW + CardIndex::Card_Count ) return 1; // Both cards YELLOW
}
// Check if player card and table card is of same value
bool ValidCard(int pcard, int tcard)
{
	// I'm still trying to figure out some witchery with division or modulus to get card offset
	// I've gone completely blank
	// Maybe something for you to do?
}

bool IsValid(int pcard, int tcard)
{
	if(ValidColour(pcard, tcard) || ValidCard(pcard, tcard)) return true; // Card is of same colour OR same value
	return false; // Card was not valid
}

int PickUp(int tcard)
{
	if(tcard == ColourIndex::BLUE + CardIndex::CP2) return 2; // table card is a blue pick-up 2
	if(tcard == ColourIndex::BLUE + CardIndex::CXP2) return 2; // table card is a blue pick-up 2
	if(tcard == ColourIndex::RED + CardIndex::CP2) return 2; // table card is a red pick-up 2
	if(tcard == ColourIndex::RED + CardIndex::CXP2) return 2; // table card is a red pick-up 2
	if(tcard == ColourIndex::GREEN + CardIndex::CP2) return 2; // table card is a green pick-up 2
	if(tcard == ColourIndex::GREEN + CardIndex::CXP2) return 2; // table card is a green pick-up 2
	if(tcard == ColourIndex::YELLOW + CardIndex::CP2) return 2; // table card is a yellow pick-up 2
	if(tcard == ColourIndex::YELLOW + CardIndex::CXP2) return 2; // table card is a yellow pick-up 2
	return 0; // Not a pick up card;
}

int main()
{
	if(!IfExists("Deck.txt")) WriteDeck("Deck.txt"); // If the deck file doesn't exist, make it
	if(!InitDeckFile("Deck.txt")) return 1; // If we couldn't init the deck exit program with error code 1

	int default_hand_number = 5; // Players start with a default number of cards in hand, feel free to change according to rules

	int player1_held_cards = default_hand_number; // Give our player the default number of cards
	int player1_current_card = GetNextCardFromDeck();

	int ai_held_cards = default_hand_number;
	int ai_current_card = GetNextCardFromDeck();

	int table_card = GetNextCardFromDeck();

	while(player1_held_cards > 0 || ai_held_cards > 0) // While player and Ai have more than 0 cards, play the game
	{
		// Player 1 turn
		player1_held_cards += PickUp(table_card); // Have they gotta pick up?
		if(IsValid(player1_current_card)) // Is their current card valid?
		{
			table_card = player1_current_card; // If so make that the new table card
			player1_held_cards--; // Decrease number of cards;
			player1_current_card == GetNextCardFromDeck(); // Get a new card
		}
		else player1_held_cards += 2; // Not a valid card, pick up 2

		ai_held_cards += PickUp(table_card); // Has the AI gotta pick up?
		if(IsValid(ai_current_card))
		{
			table_card = ai1_current_card;
			ai_held_cards--; // Decrease number of cards;
			ai_current_card == GetNextCardFromDeck(); // Get a new card
		}
		else ai_held_cards += 2; // AI card not valid, give them another 2 cards
	}
	if(player1_held_cards) std::cout << "AI Won!\n\n";
	else std::cout << "P1 won!\n\n";
}



As for the "fake array" I'd be lying if I said it was "fake". The code I suggested literally declares sequential memory (Just like an array) but without using the array subscript token int[]. I'd also like to urge you not use std::malloc or std::free, especially if you haven't done pointers or dynamic memory before.


I hope that code works or at least gives you a few suggestions on how you can do this without arrays or classes. If you need any other help let me know.

EDIT: Let me know when you are allowed to rewrite this with vectors and classes. I feel defiled teaching you programming like this and am keen to correct this way of doing things. In the link you posted, they have the right idea consolidating information and moddeling with classes. Why professors insist on people doing tasks like this without the obvious tools such as arrays and classes is beyond me. I've recently been dealing with it myself but I refuse to code like that and back pedal for the sake of them reading an assignment off a paper marked 2008 (At least in my university). They mark me down, and it kills me inside knowing I did it the correct way. /rant
Last edited on
Point-blank ask your professor how you're supposed to represent a deck and randomly pick from it without arrays/vectors.

Did your class tokenize strings at all? A deck or a player hand could be a string that looks like "R0 R1 R2 B0 B1 B2 ..." and then you could pick with a little bit of math, basically indexing the string. This would leave a sour taste in my mouth.
Aside: @metromountain, I looked briefly at your hours/minutes/seconds clock loops. Generally, red flags should be going off in your head whenever you find yourself exceeding double nested loops. Some triple- and higher constructs can still finish in a reasonable time, provided there are a lot of early-exits. Example clock generation with one loop:
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <string>

using namespace std;

int main() 
{
    int hours = 0;
    int minutes = 0;
    int seconds = 0;
    string am_pm;
    for (int counter=0; counter<86400; ++counter)
    {
        hours = counter / 3600;
        if (hours >= 12)
        {
            hours -= 12;
            am_pm = "PM";
        }
        else
        {
            am_pm = "AM";
        }
        if (hours == 0)
            hours = 12;
        
        if (hours < 10)
            cout << "0";
        cout << hours << ":";
        
        minutes = counter / 60 % 60;
        if (minutes < 10)
            cout << "0";
        cout << minutes << ":";
        
        seconds = counter % 60;
        if (seconds < 10)
            cout << "0";
        cout << seconds << " " << am_pm << endl;
    }
}


86400 lines of output
12:00:00 AM
12:00:01 AM
12:00:02 AM
12:00:03 AM
...
12:59:58 AM
12:59:59 AM
01:00:00 AM
01:00:01 AM
...
11:59:58 AM
11:59:59 AM
12:00:00 PM
12:00:01 PM
...
12:59:58 PM
12:59:59 PM
01:00:00 PM
01:00:01 PM
...
11:59:56 PM
11:59:57 PM
11:59:58 PM
11:59:59 PM


Edit: I do want to note that what I wrote is more stylistic/maintainable, but not necessarily less iterations. I think you've accidentally iterated the hours from 0..12 (13 iterations), but if you fix that, you'd also be 2*12*6*10*6*10 , or 86400, iterations.
Last edited on
@icy1

Tokenizing a string is a brilliant idea, but he didn't use std::string anywhere in his code either! He might just have to send 200 dummy parameters as arguments to his program at this rate and re-write values in argv.

I don't recommend you do that by the way MetroMountain. :-)
This is ridiculous. You can't make anything even approaching UNO without arrays in anything like a reasonable way. There is some misunderstanding here.
std::strings are pretty much a nice wrapper around a char array, anyway... I agree, there's clearly some misunderstanding here.


He might just have to send 200 dummy parameters as arguments to his program at this rate and re-write values in argv.

At that point, it would be easier to write a meta-program (using arrays) that then outputs his actual program's source code (using the 200 or so dummy variables). Sounds like fun.
@Ganado
At that point, it would be easier to write a meta-program (using arrays) that then outputs his actual program's source code (using the 200 or so dummy variables). Sounds like fun.


Even that probably wouldn't satisfy this poor soul's professor. I agree with you both something is wrong. I've tried my best to come up with something with these implausible limitations though I've seen a lot of questions like this over the years where it seems they're asked to hammer a nail with a screwdriver.
Topic archived. No new replies allowed.