Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 12th, 2006, 10:36 PM   #11
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Ok, i can't answer your question if i don't know what you want.
string cards[decksize] = "Yellow";
Now, this above will set all the elements of cards to "Yellow". So if you print all elements of cards, you'll see "Yellow", "Yellow", "Yellow",...
string cards[decksize]={"Yellow"};
the above sets the first element of cards to "Yellow", the rest stay uninitialized.
OpenLoop is offline   Reply With Quote
Old Apr 12th, 2006, 10:43 PM   #12
Cache
Hobbyist
 
Join Date: Sep 2005
Posts: 266
Rep Power: 4 Cache is on a distinguished road
Most of your loops are redundant. Such a simple task can be done with a single loop:

#include <iostream>
#include <string>
#include <vector>

#define MAX_DECK   100

int main( int argc, char *argv[] )
{
	std::vector<std::string> deck( MAX_DECK, "Yellow" );
	unsigned short int red = 0, yellow = MAX_DECK, i = MAX_DECK;
	
	do
	{
		if ( i % 2 == 0 )
		{
			deck[--i] = "Red";
			++red;
		}
	} while ( --i );
	
	yellow -= red;
	
	std::cout << "Yellow: " << yellow << "\nRed: " << red << std::endl;
	std::cin.get();
	return 0;
}
Cache is offline   Reply With Quote
Old Apr 13th, 2006, 12:03 AM   #13
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Quote:
Originally Posted by OpenLoop
Can you compute the resulting balance of 3,500,000 policies after 6,000,000+ transactions a day?
Sure. But I charge $100,000 /hr for such tasks. :p

*Sorry for posting useless comments*
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Apr 13th, 2006, 3:22 PM   #14
a3orange
Newbie
 
Join Date: Apr 2006
Posts: 14
Rep Power: 0 a3orange is on a distinguished road
I think some of you guys are misunderstanding the math problem. He first flips over all the numbers divisible by 2, then he flips over all the ones divisible by 3, then 4, etc..
a3orange is offline   Reply With Quote
Old Apr 13th, 2006, 3:57 PM   #15
a3orange
Newbie
 
Join Date: Apr 2006
Posts: 14
Rep Power: 0 a3orange is on a distinguished road
That's strange, I get different results when I do debug (with break points) then when I compile and run..

Here is my edited code:

#include <iostream>
#include <string>
using namespace std;
const int decksize = 100;
int main()
{
	string cards[decksize];
    for (int i = 0; i < decksize; i++)
    {
    cards[i] = "Yellow";
}
	int divby;
	int yellow = 100;
    int red = 0;	
	for (divby = 2; divby < decksize; divby++)
	{
        int q;
		for (q = 0; q < decksize; q++)
		{
			if ((cards[q] == "Yellow") && ((q % divby) == 0))
			{
				cards[q] = "Red";
				red++;
				yellow--;
				cout << red << "\t" << yellow << endl;

				
			}
			else if ((cards[q] == "Red")&& ((q % divby) == 0))
			{
				cards[q] == "Yellow";
				cout << red << "\t" << yellow << endl;
				red--;
				yellow++;
				cout << red << "\t" << yellow << endl;
            }
		}
	}
int n;
	for (n = 0; n < decksize; n++)
	{
		if (cards[n] == "Red")
		red++;
		else if (cards[n] == "Yellow")
		yellow++;
	}
cout << "Yellow: " << yellow << endl;
cout << "Red: " << red << endl;
cin.get();
cin.get();
return 0;
}
Thanks to all those who have helped.
a3orange is offline   Reply With Quote
Old Apr 13th, 2006, 8:04 PM   #16
a3orange
Newbie
 
Join Date: Apr 2006
Posts: 14
Rep Power: 0 a3orange is on a distinguished road
I finished my first program!!

I'm so happy:

#include <iostream>
#include <string>
using namespace std;
int main()
{
	cout << "Please input amount of cards in deck: ";
	int cards;
	cin >> cards;
	string deck[cards];
	
	for (int i = 0; i < cards; i++)
	{
		deck[i] = "Yellow"; // cycle through all cards making them yellow face up
	}
	
	int numbernow;
	int n;
	int yellow = cards;
	int red = 0;
	cout << "Yellow\t\t\tRed";
	
	for (numbernow = 2; numbernow <= cards; numbernow++)
	{
		for (n = 1; n <= cards; n++)
		{
			if (n % numbernow == 0)
			{ 
				if (deck[n-1] == "Yellow")
				{
                                   
					deck[n-1] = "Red";
					red++;
					yellow--;
					cout << endl << yellow << "\t\t\t" << red;
					continue;
				}
				if (deck[n-1] == "Red")
				{
					deck[n-1] = "Yellow";
					yellow++;
					red--;
				    cout << endl << yellow << "\t\t\t" << red;
				    continue;
				}
			}
		}
	}
cout << endl << endl << "Yellow: " << yellow << endl << "Red: " << red;
cin.get();
cin.get();
return 0;
}
a3orange is offline   Reply With Quote
Old Apr 13th, 2006, 8:06 PM   #17
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
congrats a3orange. Pretty impressive for a first program.
OpenLoop is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC