Thread: Totally lost on this project I'm doing / Beginner on C++

  1. #1
    Registered User
    Join Date
    Jul 2011
    Posts
    10

    Totally lost on this project I'm doing / Beginner on C++

    Cards and Dice Lab with Loops.pdf
    Above is the project. I am only doing the CARD DEALING as of now.
    This is what I have so far for the CARDS. I'm having trouble outputting different cards and a bunch of other stuff........BASICALLY I'M EXTREMELY BEHIND IN THIS CLASS.
    Code:
    //Dice and Cards 
    //by Lillian Wang 
    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    
    main()
    {
    int answer, cards, i;
    
    {
    
    	
    cout<<"Welcome to Dice and Cards!"<<endl<<endl;
    cout<<"1-Roll Dice"<<endl; 
    cout<<"2-Draw Random Cards"<<endl;
    cout<<"What would you like to do?(Please enter the number of choice): ";
    cin>>answer; 
    if (answer==1)
    cout<<"How many rolls would you like?: ";
    
    
    
    
    if(answer==2)
    cout<<"How many cards would you like to draw?: ";
    cin>>cards;
    	int card;
    	char value; 
    	char suit; 
    	int deck[53];
    	srand((unsigned)time(NULL));
        card=rand()%52+1; 
    for (i=1; i<=cards; i++)
    {
    	
        suit=(card-1)/13+3;
        int v=(card-1)%13+1;
    	
    	switch(v)
    	{
    	case 1:
    		value='A';
    		break;
    	case 10:
    		value='T';
    		break;
    	case 11:
    		value='J';
    	case 12:
    		value='Q';
    		break;
    	case 13:
    		value='K';
    		break;
    	default:
    		value=(char)(48+v);
    	break;
    	}
    
    cout<<value<<suit<<endl;
    }
    }
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Jul 2011
    Location
    Bangalore,India
    Posts
    24
    changes
    1) change main() to int main(void)
    2)move the card=rand()%52+1; to the first statement of the loop...so u get different cards for each draw...and u are not checking whether the card is already drawn or not....u cant show 2 same cards ith sam suit for the draws on a same deck...

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    int main() is enough, no need for the void.
    I would indent the code properly first.
    Secondly, you should properly understand scopes. If you have more than one line of code which you want executed if and only if an if statement is true, then you need to put braces around those lines.

    It would also be beneficial if you were more explicit about what you have problems with. Syntax? Logic?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    mmn..learn to use switch statement and functions
    You ended that sentence with a preposition...Bastard!

  5. #5
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    Thanks guys!! We're only allowed to use what we've learned in class so far.....if statements, arrays, LOOPS.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by golfwang View Post
    BASICALLY I'M EXTREMELY BEHIND IN THIS CLASS.
    You might think you're appealing to our sympathetic side here, but you're not really. What you are doing is showing that you're an unmotivated person who isn't actively interested in learning programming and leaves things until the last minute. If that's not you then show us a different story.
    The kind of person we want to help here is the kind of person who is well motivated to learn programming but for one reason or another just gets stuck on little things here and there, or maybe just needs some clarification or second opinion on their work. Someone who shows they're really trying to learn.

    Attempting to dump the problem on others will not get you very far. Think of us more like a physiotherapist who is helping you walk again. It's not our intention to run the race for you. We will only help as much as we can see that you are helping yourself.
    Show some real interest in what you are doing. Describe what you're trying to do, and describe what isn't working or what you aren't sure how to do. Just pick one bit that you aren't sure of and start there. Have a go and when you can't figure it out, come and ask about it. Then when we're helped you understand how to solve that bit, work on the next bit.

    You're not getting many responses so far because you're not doing these things. I've done you a favour by telling you how you can present yourself as someone who others will actually want to help.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    @iMalc: Hope you enjoyed wasting your time writing that, because I honestly wasn't looking for any sympathy whatsoever! Anyways I have the program all figured out now. Thanks though. =)
    Last edited by golfwang; 07-24-2011 at 08:10 PM.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Do you truly have to be so condescending? Did iMalc write that just to be an ..............? I think not. I think iMalc did it for YOUR sake. Now you can imagine how it looks like when you reply like that.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jul 2011
    Posts
    10
    @Elysia: Yeah, I know he did. I thanked him! Since I'm new to this whole board thing, he clarified what I needed to write if I needed help next time and to not just throw something out and wait for people to reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. totally lost.
    By ain in forum C Programming
    Replies: 12
    Last Post: 02-06-2011, 05:12 AM
  2. C++ Concepts - not totally lost
    By Elysia in forum C++ Programming
    Replies: 3
    Last Post: 10-16-2010, 04:13 PM
  3. Help, home work code provided. Totally Lost.
    By 1BadRbt in forum C Programming
    Replies: 18
    Last Post: 12-04-2006, 03:18 PM
  4. Totally lost beginner
    By burrissa in forum C Programming
    Replies: 7
    Last Post: 03-29-2004, 08:00 PM
  5. i'm totally lost
    By jlmac2001 in forum C++ Programming
    Replies: 5
    Last Post: 02-01-2003, 11:06 PM