1 Replies - 641 Views - Last Post: 04 January 2010 - 07:55 PM

#1 fishmonger   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-January 10

Hea I'm new here and to programming

Posted 04 January 2010 - 07:49 PM

Hello, I'm a new programming student and I'm currently employed as a meat cutter/fish-man in a supermarket. Just switched from CET to a Programming AS at a local Community College and I'm brand spanking new to programming. My only knowledge comes from Absolute Beginner's Guide to C. About finished reading it. Thinking of moving on to The C Programming Language if I'm able to understand it.

I've practiced a bit programming in C, my chosen starter language. Now, working on a poker game. I've attached code for "Rock, Paper, Scissors" that I wrote today while noodling around for practice.

I'm admittedly very inexperienced and I know I'm lacking in the math department, not really bad at math just was a very undisciplined home-schooler growing up and didn't apply myself. So I'm playing catch up in math, but I do have discipline now and a lot of eagerness to learn everything I can about programming. My goal is to be well rounded and employed as soon as possible. I don't want short-cuts. I understand to be good I have to work extremely hard.

By reading/posting on this site I hope to get some pointers on how and what to study to make the most of my effort. Feel free to comment on the code bellow. Not sure what you can gather from it because it's very simple, but if you see me lacking in one respect or many please point me in the right direction. Thanks and see you around. :D

#include "stdafx.h"
#include "iostream"
#include "string"
#include <stdlib.h>
#include <time.h>
int _tmain(int argc, _TCHAR* argv[])
{
char choice;
int opponent;
char play = 'y';
int pScore;
int playerWin = 0;
int opponentWin = 0;

time_t t;
srand(time(&t));
while (play == 'y')
{
printf("Rock Paper Scissors\n\n");
printf("Player Wins %d\n", playerWin);
printf("Opponent Wins %d\n", opponentWin);
printf("Choose Wisely......\n");
printf("Type r, p, or s\n");
scanf(" %c", &choice);
	switch (choice)
	{ case ('r') : printf("You Choose Rock!\n");
					pScore = 1;
					break;
	  case ('p') : printf("You Choose Paper!\n");
					pScore = 2;
					break;
	  case ('s') : printf("You Choose Scissors!\n");
					pScore = 3;
					break;
	  default	 : printf("You Fool There Are Only 3 Choices!\n");
					break;
					
	}
	if ((choice!='r') && (choice!='p') && (choice!='s'))
		{ continue;}


opponent = (rand() % 3) + 1;
	switch (opponent)
	{ case (1) : printf("Your Opponent Chose Rock!\n");
					break;
	  case (2) : printf("Your Opponent Chose Paper!\n");
					break;
	  case (3) : printf("Your Opponent Chose Scissors!\n");
					break;
	  default	 : printf("Silly Computer There Are Only 3 Choices!\n");
					break;
					
	}

	if (pScore == opponent) { printf("Tie!\n");}
	if ((pScore == 1) && (opponent == 2)) { printf("Paper Covers Rock!\nYou Lose!\n"); opponentWin++;}
	if ((pScore == 2) && (opponent == 3)) { printf("Scissors Cut Paper!\nYou Lose!\n"); opponentWin++;}
	if ((pScore == 3) && (opponent == 1)) { printf("Rock Crushes Scissors!\nYou Lose!\n"); opponentWin++;}
	if ((pScore == 3) && (opponent == 2)) { printf("Scissors Cut Paper!\nYou Win!\n"); playerWin++;}
	if ((pScore == 2) && (opponent == 1)) { printf("Paper Covers Rock!\nYou Win!\n"); playerWin++;}
	if ((pScore == 1) && (opponent == 3)) { printf("Rock Crushes Scissors!\nYou Win!\n"); playerWin++;}

printf("Play Again?\nType y or n\n");
scanf(" %c", &play);

		}
printf("Player Wins %d\n", playerWin);
printf("Opponent Wins %d\n", opponentWin);




	
std::cout << "Press the enter key to exit";
std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);
	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Hea I'm new here and to programming

#2 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1660
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Hea I'm new here and to programming

Posted 04 January 2010 - 07:55 PM

Welcome to Dream.In.Code

Thanks for joining Dream.In.Code, hope to see you around the forums someday :)

You have just stepped into the greatest programming community on the Internet, we have experts for just about every mainstream language, and even some languages that aren't so mainstream, so the level of expertise is second to none. All will be more than willing to help, as long as you too are willing to put forth the effort to solve your problem, and to go along the road to becoming a better programmer smile.gif

I would like to ask that when making a programming question that you first place your code inside code tags like this :code: . This makes it much easier to read through large pieces of code, and keeps your post a little more organized.

When posting a programming question first make sure you're in the first forum, then make sure you provide as much information as you can think of that would make it easier for a 2nd pair of eyes to help you debug your issue.

If you happen to get bored (I know, it's real hard to do here) you can check out our Off Topic Caafeine Lounge, the Corner Cubical, dedicated to industry talk, or the Student Campus, dedicated to all things for students.

If you have any questions or concerns please do not hesitate to contact myself or another staff member, and we will be more then happy to answer any questions you might have.


-Richard
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1