Write it and find out!
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Code:#include <math.h>#include <stdio.h> #include <stdlib.h> #include <time.h> #include <conio.h> unsigned long playerone() { int dice, risk1 = 0; unsigned long score; char keypress; keypress = ''; score = 0; turn1:; srand(time(NULL)); dice = 1+(rand()%6); printf("\n player1 dice = %d", dice); if(dice == 1) { score = 0; goto exitturn1; } score = score + (unsigned long)dice; printf("\n Would you like to risk it? (-1 for no)"); scanf("%d", &risk1); if(risk1 == -1) { goto exitturn1; } goto turn1; exitturn1:; printf("\n player1 score = %lu", score); return(score); } unsigned long playertwo() { int dice, risk2 = 0; unsigned long score; char keypress; keypress = ''; score = 0; turn2:; srand(time(NULL)); dice = 1+(rand()%6); printf("\n player2 dice = %d", dice); if(dice == 1) { score = 0; goto exitturn2; } score = score + (unsigned long)dice; printf("\n Would you like to risk it? (-1 for no)"); scanf("%d", &risk2); if(risk2 == -1) { goto exitturn2; } goto turn2; exitturn2:; printf("\n player2 score = %lu", score); return(score); } int main() { unsigned long tally1, tally2, sum1, sum2; sum1 = 0; sum2 = 0; start:; printf("\n\n\n"); tally1 = playerone(); sum1 = sum1 + tally1; printf("\n player1 tally: %lu", sum1); if(sum1 >= 100) { printf("\n player one wins"); goto exitprg; } printf("\n"); tally2 = playertwo(); sum2 = sum2 + tally2; printf("\n player2 tally: %lu", sum2); if(sum2 >= 100) { printf("\n player two wins"); goto exitprg; } printf("\n\n\n\n\n Please press a key to continue. Thank you!"); getch(); goto start; exitprg:; return(0); }
Yeah it's almost like why bother trying and getting used to solving problems.laserlight is right however these programs are very hard and uses a lot of functions
I hope the OP takes the opportunity to write something better, 'cause chances are it will be. OP might know how to use a loop.
Jesus Christ! Bless GOD, Jesus Christ, The Holy Spirit, and Mary# Then bless my real mom Huong Thi Thuyen Vu. Honours to my real mom Huong Thi Thuyen Vu. Honours to my real dad Nguyen Binh Thuy. Congratulations to my real two sisters Nguyen Khoa Thuyen and Nguyen Khoa Thi. whiteflags: you are right. If you try to be better you will be better, but GOD gives each person a gift. I'm only five foot five inches tall. So I don't have the gift to be a basketball dunker. So the trick is knowing where your talent is and going with it. If you are more left brain then you are more logical and prefer reality. If you are right brain you are more intuitive and know things more like 'I feel this is right' and it ends up being right. I've been trained with BASIC from 9 years old so gotos statements are a part of me now. Thank you Jesus Christ. P.S. If you notice your numbers to English is extremely efficient compared to mine. Amen.
If have also started with BASIC in the 1980's (on TI-99/A4 and Commodore 64). But a few years later (1990's) my BASIC-programs havn't 'goto' anymore.
BASIC have also 'if' and 'for' to control a program. Functions can be build in BASIC with 'gosub', 'on # gosub' and 'return'.
So, please don't recommend 'goto'!
Also, please don't recommend to include 'conio.h'! It is deprecated and outdated!
Last edited by WoodSTokk; 07-03-2016 at 02:26 PM.
Other have classes, we are class
Good.whiteflags: you are right.
Even so I want to make this request now: next time you want to try someone's homework, could you write it, and start a new thread, so that we can talk about your code?If you try to be better you will be better, but GOD gives each person a gift.
I will get to the reasons why, but I need to respond to the excuses you gave for behavior.
I wish you would give us the same respect you give basketball players and stay off our court.I'm only five foot five inches tall. So I don't have the gift to be a basketball dunker.
Well, it's a bad way to program, the computer doesn't care about how you feel.So the trick is knowing where your talent is and going with it. If you are more left brain then you are more logical and prefer reality. If you are right brain you are more intuitive and know things more like 'I feel this is right' and it ends up being right.
Hey! You said something that actually makes some sense.I've been trained with BASIC from 9 years old so gotos statements are a part of me now.
Well, I don't know about your experience. You've lied about it before in other places so the reality of the situation will be forever muddy. But the thing is, learning to program C or C++ by making it look like BASIC is not doing anyone, even yourself, a favor. What I don't want to happen is someone comes along with a problem that is just easy enough for you to solve, and you post your C++/BASIC mixture from hell. Then, depending on their own experience, they might think that is what someone normal with a working knowledge does.
I certainly hope you agree with me that you don't have a working knowledge. You don't know how to write a program that someone would actually want to read. But again, you just post code! No explanation, no context, just your attempt.
If you want to do that, fine, but I think you deserve your own thread, where we can talk to and about you specifically without introducing your bad habits to anyone else. They have their own issues with the problems that they post. They deserve the right to solve it their own way, not your way. Because when you post the answer to a problem, it mostly ruins the fun. People who deserve to see other solutions usually put in substantial effort first. For example, they might post a short, self contained, compileable example which gets fixed. Then, someone comes along with separate but functional improvements or ideas.
Right now you can't really help everyone. C/C++ is not BASIC. No one should see that.
You are certainly right about some things? I write program that works. I expect that a real world situation is where a program just works! If you nitpick you may never get the job done on time and on schedule. We are talking about C. Although it veries to some extent from one C to another C it is still C. What I agree with to some extent is the homework part. I believe a person should and MUST do their own work. However if there is a problem then when the person posts THEIR work others can give suggestions on what may be the solution to a bottleneck. Sometimes people need a jump start. They are so lost because it is their very first time that they mess it all up and give up even for life. The idea of a school is to graduate and eventually get them a job. Not all schools are able to hold a perfect 100% success rate of doing that. The idea of a school is to train an individual to integrate into society with their chosen expertise.
It may work but it wouldn't pass a code review; after all it looks more like a really ancient BASIC program than a C program.I expect that a real world situation is where a program just works! If you nitpick you may never get the job done on time and on schedule.
Hail Satan!
Official Church of Satan Website | churchofsatan.com
Edit: the purpose of homework is for people to learn, so don't do their homework for them.
You accuse me of lying about my experiences before. I have NEVER once lied about my experiences. I went to Lehigh Carbon Community Colllege in the state of Pennsylvania from 1990 to approximately 1996 with a gap in 1994 and another year to transfer credits to other University/colleges. My father always wanted me to graduate from Lafayette College because it is a good engineering school. I got in for a summer semester however I didn't want to continue so I went to California and messed around a bit. When I was just a kid my dad bought me a computer that I programmed on at 8/9 years old. I've had computers throughout my life since then. All in all I have probably an equivalency of a 2-year Liberal Arts Associates Degree. In fact officially I am missing one course credit from getting my official Associates Two Year Degree. The policy may have changed where I have to retake courses to refresh my mind. I don't want to brag however I feel strong confidence I am able to do a humble amount of things. I've taken official courses in college of Pascal, COBOL, FORTRAN, SQL, ... that's off the top of my head. When I was 9 I learned BASIC for the Commodore 64 computer. In 2014 I learned Borland Turbo C 2.01 and Borland Turbo Assembler 4.1. I've specialized in both especially assembly for the last two years. Now I like you but I've got a girlfriend. Anyways, I just wanted to get the facts straight. No hard feelings. I don't mean to put you down but you should stop going with the crowd. You have a lot of talent and I appreciate that intelligence.
OMG such an over-reaction to critic of poorly written code.
White Flags is fully justified to give responses of what is written, and of course
you can fully agree or dis-agree with it as free will dictates. However, there is
being in dis-agreement and there is going overboard.
C is a functional procedural language and should be used in this way of course.
There are no strict rules saying you must write code like this or that, but using
goto labels confuse the program and logic of the code. A goto label in C anyway,
should only be used in extreme situations, such as exiting from a deeply nested loop
or routine where using a simple break statement would not logically work.
I am not saying what you wrote is invalid, I am just trying to explain why other users
are justified in the practice of the goto statement.
Double Helix STL
Remember bumping into this article a while back, relevant to the goto discussion: Using Goto in Linux Kernel Code | Koblents.com