C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old November 16th, 2009, 03:04 PM
Beaverbash2 Beaverbash2 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2009
Posts: 1 Beaverbash2 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 25 sec
Reputation Power: 0
Random Number problem!

Ok so basically we have to create a program that "deals" the user and the computer 5 cards each. It then declares the winner based on the one with the highest card.

example output:
Your cards are: 3 14 K 5 9
The computer's cards are: 5 J 10 2 J
You have the single highest card value. you won!

Any help would be very greatly appreciated!

This is the code I have so far:
//High Card Game

#include <iostream>

#include <ctime>

using namespace std;

int main ()

{
srand(time(0));
int user, computer;

int counter = 0, high = 0;

while (counter < 5)

{

user = rand()%10+4;

if (user > high)

{

high = user;

}

counter++;

}
while (counter < 5)

{


computer = rand()%10+4;

if (user > high)

{

high = user;

}

if (computer > high)

{

high = computer;

}

counter++;

}


if (user = 11)

{

user = 'J';

}

if (user = 12)

{

user = 'Q';

}

if (user = 13)

{

user = 'K';

}

if (user = 14)

{

user = 'A';

}

if (computer = 11)

{

computer = 'J';

}

if (computer = 12)

{

computer = 'Q';

}

if (computer = 13)

{

computer = 'K';

}

if (computer = 14)

{

computer = 'A';

}





cout<<"Your cards are:"<<user<<user<<user<<user<<user<<endl;

cout<<"The computer's cards are:"<<computer<<computer<<computer<<computer<<computer<<endl;

if (computer > user)

{

cout<<"The computer has the highest single card."<<endl;

}

else if (user > computer)

{

cout<<"You have the highest single card."<<endl;

}

else if (user = computer)

{

cout<<"You and the computer are tied fot the highest single card."<<endl;

}


return 0;

}

Reply With Quote
  #2  
Old November 17th, 2009, 01:32 PM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Click here for more information.
 
Join Date: Dec 2007
Posts: 990 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 15 h 32 m 39 sec
Reputation Power: 3
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
First, I recommend you separate your "how to display this card" into a function of its own. I suggest the function signature string display(int);

Then, you should be using several variables, preferrably in a vector or array, to store the card values.
vector<int> userhand(5);
for (int i=0; i<5; i++) userhand[i]=rand()...
__________________
Quote:
Programming by Coincidence
Fred types in some more code, tries it, and it still seems to work. [Then] the program suddenly stops working. [...] Fred doesn’t know why the code is failing because he didn’t know why it worked in the first place.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Random Number problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 7 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek