GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jul-2004, 00:21
teh0ni0n teh0ni0n is offline
New Member
 
Join Date: Jul 2004
Posts: 3
teh0ni0n is on a distinguished road

Need help making a program


Heres a descripton of what I need help making, It will be a console C++ program

" A deck of cards has 4 suits and 13 values in each suit. It contains 52 cards. The program needs to display the value and suit given a number. Hint: A suit is <value> % 4 where 0 is Hearts, 1 is Spades, 2 is Diamonds and 3 is Clubs. Use argc and argv in this program. "

I really have no idea how to do something like this, i'm just a noob! Anybody help?
  #2  
Old 08-Jul-2004, 00:49
sho sho is offline
Junior Member
 
Join Date: Jun 2004
Posts: 49
sho will become famous soon enough

just a little help


you should read a little to do it... its easier than you think...

here are some hints:

CPP / C++ / C Code:
// here is your main function with the arguments you need to use:
void main(int argc, char *argv[]) {
    // put here your code
}
1) the variable argv[] has a value or more
2) you take its value(s) and perform a modulo operation with 4 (var % 4)
3) if the result is 0 the suit is Hearts, if is 1 is Spades, 2 is Diamonds and 3 is Clubs
4) so use a conditional operator to do one thing or other depending on that
5) also depending on that you should peform some operation to the value(s) to find the value of the card being represented

hope this helps...
  #3  
Old 08-Jul-2004, 01:08
teh0ni0n teh0ni0n is offline
New Member
 
Join Date: Jul 2004
Posts: 3
teh0ni0n is on a distinguished road
Quote:
Originally Posted by sho
you should read a little to do it... its easier than you think...

here are some hints:

CPP / C++ / C Code:
// here is your main function with the arguments you need to use:
void main(int argc, char *argv[]) {
    // put here your code
}
1) the variable argv[] has a value or more
2) you take its value(s) and perform a modulo operation with 4 (var % 4)
3) if the result is 0 the suit is Hearts, if is 1 is Spades, 2 is Diamonds and 3 is Clubs
4) so use a conditional operator to do one thing or other depending on that
5) also depending on that you should peform some operation to the value(s) to find the value of the card being represented

hope this helps...

CPP / C++ / C Code:
// Cards.cpp 
//
#include "stdafx.h";
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	int number;
	int suit;

	cout << "Please tell me a number"<<endl;
	cin >> number;
	suit  = (number % 4);
	cout << "The Suit is ";

	if (0 == suit)
		cout << "Hearts"<<endl;

	if (1 == suit)
		cout << "Spades"<<endl;

	if (2 == suit)
		cout << "Diamonds"<<endl;

	if (3 == suit)
		cout << "Clubs"<<endl;



	return 0;
}

Thats what I have right now, But I'm having trouble figuring out the value, like king queen jack 10 etc because i dont play cards! Any ideas?
Last edited by LuciWiz : 25-Mar-2006 at 11:08. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #4  
Old 08-Jul-2004, 01:14
teh0ni0n teh0ni0n is offline
New Member
 
Join Date: Jul 2004
Posts: 3
teh0ni0n is on a distinguished road
Quote:
Originally Posted by teh0ni0n
Thats what I have right now, But I'm having trouble figuring out the value, like king queen jack 10 etc because i dont play cards! Any ideas?


CPP / C++ / C Code:

// Cards.cpp 
//
#include "stdafx.h";
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	int number;
	int suit;
	int value;

	cout << "Please tell me a number"<<endl;
	cin >> number;
	suit  = (number % 4);
	cout << "The Suit is ";

	if (0 == suit)
		cout << "Hearts"<<endl;

	if (1 == suit)
		cout << "Spades"<<endl;

	if (2 == suit)
		cout << "Diamonds"<<endl;

	if (3 == suit)
		cout << "Clubs"<<endl;
	
	cout << "And the value is ";
	value = (suit % 13);

	if (0 == value)
	cout << "King"<<endl;


	return 0;
}


I figured out how to find the value, you can see i'll just add 12 more ifs at the end, But I have no idea what names match what values!! Like what value is king etc!
  #5  
Old 08-Jul-2004, 03:12
sho sho is offline
Junior Member
 
Join Date: Jun 2004
Posts: 49
sho will become famous soon enough
oh so the main problem was actually a cards problem

card numbers go from 1 to 13...
1 is the as
2 to 10 are numbers
11 is jack
12 is queen
13 is king

just some advice in your code:

CPP / C++ / C Code:
// Cards.cpp 
//
#include "stdafx.h";
#include <iostream>
using namespace std;

int main(int argc, char* argv[])
{
	// the problem says to use argc and argv to get the number so:
	int number = argv[0]; // but argv can contain more than one number so check it out with argc
	int suit;
	int value;

	// the next isnt needed since the number will be extracted from argv
	// cout << "Please tell me a number"<<endl;
	// cin >> number;
	suit  = (number % 4);
	cout << "The Suit is ";

	if (0 == suit)
		cout << "Hearts"<<endl;

	if (1 == suit)
		cout << "Spades"<<endl;

	if (2 == suit)
		cout << "Diamonds"<<endl;

	if (3 == suit)
		cout << "Clubs"<<endl;
	
	cout << "And the value is ";

	// i think from what the problem says that the number will be
	// a number between 0 and 52
	// multiples of 4: hearts.. numbers with %4 == 1: spades.. and so on
	// so 4,8,12,16...52 are hearts... being 4 the value 1 of hearts...
	// number 52 is the value 13 of hearts... and so on
	// and thats how you can do it
	value = (suit % 13);

	if (0 == value)
	cout << "King"<<endl;

	return 0;
}

  #6  
Old 08-Jul-2004, 22:04
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,258
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Build and run this program with different parameters at the console. It should give you an idea how to deal with the command line:
CPP / C++ / C Code:
#include <stdio.h>

int main (int argc, char *argv[])
{
    int p;    // parameter loop

    printf("%d arguments \n", argc);  // number of parameters on cmd line
    for (p=0; p<argc; p++)
    {
        printf("%02d) %s \n", p, argv[p]);
    }
    return 0;
}
Remember, all parameters are char*, even if using C++. So if you enter a number you'll have to convert it from the char string to an integer.
__________________

Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough.
-- Pearl Williams
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with a C program (Long) McFury C Programming Language 3 29-Apr-2004 21:06
Modify a C program ayoub C Programming Language 3 15-Mar-2004 12:34
error during program rjd72285 C++ Forum 0 11-Nov-2003 19:49
one program access another? dgoulston C++ Forum 1 07-Oct-2003 12:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 02:35.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.