![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Ok, i can't answer your question if i don't know what you want.
string cards[decksize] = "Yellow"; string cards[decksize]={"Yellow"}; |
|
|
|
|
|
#12 |
|
Hobbyist
Join Date: Sep 2005
Posts: 261
Rep Power: 4
![]() |
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;
} |
|
|
|
|
|
#13 | |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Quote:
*Sorry for posting useless comments*
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
|
#14 |
|
Newbie
Join Date: Apr 2006
Posts: 14
Rep Power: 0
![]() |
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..
|
|
|
|
|
|
#15 |
|
Newbie
Join Date: Apr 2006
Posts: 14
Rep Power: 0
![]() |
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;
} |
|
|
|
|
|
#16 |
|
Newbie
Join Date: Apr 2006
Posts: 14
Rep Power: 0
![]() |
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;
} |
|
|
|
|
|
#17 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
congrats a3orange. Pretty impressive for a first program.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|