Thread: Challange for Cprogramming.com

  1. #16
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    >> I agree, this is a new stragety for homework.

    Anyone else remember the people posting their homework questions in the Contests Board? It's so genius that if I were a mod I'd've overlooked it

  2. #17
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    Arrow

    Hi Guys,

    You have made me very disappointed. i was not here for my homework, just here to help someone. i have made many efforts in writing that code, but failed, you can see my attempts ... i again said Not everyone here for home work, there may be some other purpose...

    Code:
    #include <iostream.h>
    void main(){
    	char value;
    	int c,num,sum;
    	int total,aces,done;
    	cout << "How many cards do you have? (2-5)";
    	cin >>total;
    		
    	c=1;
    	sum=0;
    	aces=0;
    	while (c<=total){
    		cout<<"Input value of card #"<<c<<" (2-9 or j,q,k,a)";
    		cin>>value;
    		if (value=='2'){
    			num=2;
    			}
    		elseif (value=='3'){
    			num=3;
    			}
    		elseif (value=='4'){
    			num=4;
    			}
    		elseif (value=='5'){
    			num=5;
    			}
    		elseif (value=='6'){
    			num=6;
    			}
    		elseif (value=='7'){
    			num=7;
    			}
    		elseif (value=='8'){
    			num=8;
    			}
    		elseif (value=='9'){
    			num=9;
    			}
    		elseif (value=='t'){
    			num=10;
    			}
    		elseif (value=='j' || value=='q' || value=='k'){
    			num=10;
    			}
    		elseif (value=='a'){
    			num=11;
    			aces++;
    			}
    
    		sum=sum+num;
    		c++;
    		}
    	
    	
    
    	if (sum>21){
    		if (aces>0){
    			c=0;
    			done=0;
    			while (done!=1){
    				sum=sum-10;
    				aces=aces-1;
    				if (aces==0 || sum<=21){
    					done=1;
    					}
    				}
    			}
    		}
    
    	If (sum>21){
    		cout << "Busted";
    		}
    	else{
    		cout <<sum;
    		}
    
    }

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    i was not here for my homework, just here to help someone.
    i.e., here to help someone else get his/her homework done? Either way the homework policy applies, and you have pretty much attempted to mislead the community here by making it seem like a friendly "challenge" (which should be in the contests forum anyway, as noted by twomers ).
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Registered User
    Join Date
    Apr 2007
    Posts
    7
    now can you help me, what i have done wrong in that program ??

  5. #20
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    now can you help me, what i have done wrong in that program ??
    I shall be nice this time round:

    1. You used <iostream.h> instead of the standard <iostream> header.
    2. You used void main() instead of the standard int main().
    3. You used If instead of if (C++ is case sensitive for keywords).

    You could simplify the handling of your card input by checking for ranges, but that should affect whether the code compiles or not. Note that I have not checked your logic.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #21
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That long if-elseif statement could be replaced with a switch statement, but that's just a suggestion. BTW, "elseif" is two words, "else if".
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #22
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Also "elseif" should be two words, as in "else if"
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #23
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Also "elseif" should be two words, as in "else if"
    Oops, the dangers of alternating between C++ and PHP message boards
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #24
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    You'd also need an argument as to whether or not an ace is a '1' or an '11'. Something like;

    Code:
    		else if (value=='a'){
    		
    		    if(sum>11)
    		     {
    		       num=1;
    		       aces++;
    		      }
    	               else{
            		   num=11;
            		   aces++;
            		 }
    		
    
    		sum=sum+num;
    		c++;
    		}

  10. #25
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Well, his six hour deadline that he told us about has already passed.

    What are the Vegas odds he passed/failed the assigment?

  11. #26
    Registered User
    Join Date
    Dec 2006
    Location
    Scranton, Pa
    Posts
    252
    Personally, it's not in my nature to be mean-spirited, but some of you Guys n' Dolls have been around a long time, so I imagine that wears on your patience. No doubt, you've seen it all. If the person posted the code first off though, he would have received plenty of help and his task would have been completed in no time.

    I certainly understand members sayin', show you code, then we'll help.

  12. #27
    Registered User
    Join Date
    Nov 2004
    Location
    Pennsylvania
    Posts
    434
    Yup, that's the policy, even if it was homework if he posted a good effort and really tried, we could help him out, hell, half the stuff i've learned i've learned from here. No book in the world compares to this community. But when someone just posts something that is called a "Contest" without code then to us it sounds like "Homework"

    Like i said, if he/she did it right the first time we never would've gotten into this =P

    haha
    "Anyone can aspire to greatness if they try hard enough."
    - Me

  13. #28
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    @ Wraithan, that dictionary says it is Slang in all its usages and all of the sources are cited as being American, I count that as an American word not a proper English word.

  14. #29
    Registered User
    Join Date
    Apr 2007
    Posts
    45
    The whole point of being set work is that they learn from attempting to do it (as opposed to passively just listening to or reading rules).

    Kinda how most decent programmers learn

    We had a guy at our place recently (now fired) who would say to me "what can I do at home to improve my ability?"

    lol?

    I told him to go home and write programs to do stuff.................

    This guy had a 1st in CS.
    we are one

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A challange
    By Ahmed29 in forum C++ Programming
    Replies: 39
    Last Post: 11-03-2008, 09:25 PM
  2. Digit selector... (Mathmatically complex, for some)
    By Axpen in forum C Programming
    Replies: 17
    Last Post: 08-28-2004, 02:58 PM
  3. Stuck on a friend's challange
    By wiresite in forum C++ Programming
    Replies: 32
    Last Post: 04-23-2004, 07:36 AM
  4. Timecard Challange
    By Thantos in forum Contests Board
    Replies: 2
    Last Post: 11-20-2003, 04:12 PM
  5. Chess Challange
    By kosmoludek in forum C Programming
    Replies: 4
    Last Post: 01-12-2003, 04:53 PM