Looking for a mentor, of sorts

This is a discussion on Looking for a mentor, of sorts within the C Programming forums, part of the General Programming Boards category; Firstly, I'd just like to say hey to all that read these boards. I was wondering if any of you ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Location
    Plymouth, U.K.
    Posts
    13

    Looking for a mentor, of sorts

    Firstly, I'd just like to say hey to all that read these boards.

    I was wondering if any of you could give up 20 minutes a day (if that) and help me out with my learning. What I mean is if you could set me a task (like they do on the courses at uni) so I could write the code for it, and then you could give me feedback on whether I could make it more efficient etc. The reason for asking is I don't really know of programs that would require most of the things I'm trying to practice, so it would benefit me greatly.

    Thanks in advance,
    Ben.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Between writing up assignments, answering questions, and grading/critiquing, what you're asking would be much more than a 20 minute job. It's tough to put that time aside for a single person, especially for free.

    If you can't afford to pay anyone, then your best bet for more real-time personal teaching is a chatroom. DalNet has a C++ chatroom and the admins can be quite friendly with explaining a subject to you. Any specific questions, you can feel free to post on a message board like this. I would seriously doubt you'll get anyone to tutor you for nothing, though.

    Best of luck finding what you need.
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Apr 2006
    Location
    Plymouth, U.K.
    Posts
    13
    I guess I put the wrong idea across. When I say the above, I meant all you'd have to do is tell me a program to code so I can practice. Sorry for the confusion. Would that be irc.dal.net?

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Quote Originally Posted by Mindphuck
    Would that be irc.dal.net?
    Yes, that's correct.

    Just tell me what you think you know and we'll give you a program to write.
    Sent from my iPadŽ

  5. #5
    Registered User ortegac's Avatar
    Join Date
    Mar 2006
    Location
    In front of the computer screen
    Posts
    15

    Here is your home work

    ok I dont know if i can give you 20 minutes. But i will sure try to help you out. I will be checking this forum almost every day. Here is what is a program that i think is good for you.

    <quote>
    The topic is "Decision and Control Statements"
    Given an amount of money (less than $1.00), compute the number of quarters, dimes, nickels, and pennies needed.
    </quote>

    Tell me if you can do this. Try to do it in your own.

    Caleb

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    Ahh, knapsack problem. Classic

    Extra: try finding ALL solutions, or the solution requiring the least number of coins. Or handle any amount ($77628.39?), and do all standard currency denominations
    Last edited by jafet; 04-03-2006 at 02:13 AM.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Location
    Plymouth, U.K.
    Posts
    13
    Well, I was given the challenge of writing a Rock, Paper, Scissors game, which I think I've done quite efficiently:

    Code:
    /* 
       rps.c
       open source terminal game
       this is just a commandline version of everyone's favourite game, "Rock, Paper, and Scissors."
    */
     
    #include <stdio.h>
    #include <math.h>
    #include <time.h>
     
    int main(){
        srand (time(NULL));
        int computer = rand() % 3;
        int player;
        printf("\nPlease select which object you wish to use.\n(rock = 0, paper = 1, scissors = 2): ");
        scanf("%d", &player);
        switch(player){
                       case 0:{
                            if(computer == 0){
                                        printf("It was a draw! You both picked rock!\n");
                                        break;
                                        }
                            if(computer == 1){
                                        printf("I'm sorry, Computer beat you with his paper to your rock.\n");
                                        break;
                                        }
                            if(computer == 2){
                                        printf("Good job! You beat Computer with your rock to his scissors!\n");
                                        break;
                                        }
                            }
                       case 1:{
                            if(computer == 1){
                                        printf("It was a draw! You both picked paper!\n");
                                        break;
                                        }
                            if(computer == 2){
                                        printf("I'm sorry, Computer beat you with his scissors to your paper.\n");
                                        break;
                                        }
                            if(computer == 0){
                                        printf("Good job! You beat Computer with your paper to his rock!\n");
                                        break;
                                        }
                            }
                       case 2:{
                            if(computer == 2){
                                        printf("It was a draw! You both picked scissors!\n");
                                        break;
                                        }
                            if(computer == 0){
                                        printf("I'm sorry, Computer beat you with his rock to your scissors\n");
                                        break;
                                        }
                            if(computer == 1){
                                        printf("Good job! You beat Computer with your scissors to his paper!\n");
                                        break;
                                        }
                            }
        }
        return(0);
    }
    I'll get working on the challenge you two have set me :P

  8. #8
    Registered User
    Join Date
    Apr 2006
    Location
    Plymouth, U.K.
    Posts
    13
    Code:
    #include <stdio.h>
    
    int main(){
        short int quartercount = 0;
        short int dimecount = 0;
        short int nickelcount = 0;
        short int centcount = 0;
        double money;
        printf("Please insert the amount of money less than $1.00 to be converted into quarters, dimes, nickels, and cents: ");
        scanf("%lg", &money);
        if(money > 0.99 || money < 0){
                 printf("I'm sorry, the amount you entered was not between $0.00 and $1.00.");
                 return(0);
                 }
        else{
             centcount = money * 100;
             while(centcount >= 25){
                      centcount = centcount - 25;
                      quartercount++;
                      }
             while(centcount >= 10){
                      centcount = centcount - 10;
                      dimecount++;
                      }
             while(centcount >= 5){
                      centcount = centcount - 5;
                      nickelcount++;
                      }
             printf("%lg represented in the lowest amount of coins possible is: %d quarters, %d dimes, %d nickels, and %d cents.",money,quartercount,dimecount,nickelcount,centcount);
             }
        return(0);
    }
    Satisfactory? :P
    Last edited by Mindphuck; 04-03-2006 at 01:29 PM. Reason: Wrong code.

  9. #9
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Quote Originally Posted by Mindphuck
    Satisfactory? :P
    Looks good to me.

    Here's another option you can turn into a second version:
    Code:
    int coinvals[] = {25, 10, 5, 1, 0};
    int coinneed[] = { 0,  0, 0, 0};
    int coin;
    ...
    coin = 0;
    while (coinvals[coin] > 0)
    {
        while (centcount >= coinvals[coin])
        {
            centcount = centcount - coinvals[coin];
            coinneed[coin]++;
        }
        coin++;
    }
    Try that on for size
    It's a little more advanced, and a little shorter on the code. Uses the idea that each 'coin' is processed identically, so you have one processing loop that can handle all the different coins.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

  10. #10
    Registered User ortegac's Avatar
    Join Date
    Mar 2006
    Location
    In front of the computer screen
    Posts
    15

    Very good!

    You did it in a short time!

    Now try this!

    <code>
    Write a program that, given the number of hours an employee worked and the hourly wage, computes the employee's weekly pay. Count any hours over 40 as overtime at time and a half.
    </code>

  11. #11
    Registered User
    Join Date
    Apr 2006
    Location
    Plymouth, U.K.
    Posts
    13
    Here you go
    Code:
    #include <stdio.h>
     
    double weeklywage (unsigned int hours, double hourlypay){
        return (hours * hourlypay);
    }
        
    double overtime (unsigned int hours, double hourlypay)
    {
            double overtime = hours + ((double)hours / 2);
            double overtimepayment = overtime * hourlypay;
            return (overtimepayment);
    }
     
    int main ()
    {
        unsigned int hours = 0;
        unsigned int overtimehours = 0;
        double hourlypay = 0;
        double payment = 0;
     
        printf ("How many hours did this employee work this week: ");
        scanf ("%d", &hours);
        
        if(hours > 40){
                 overtimehours = hours - 40;
                 hours -= overtimehours;
                 }
     
        printf ("How much is the hourly rate for this employee: ");
        scanf ("%lg", &hourlypay);
     
        payment = weeklywage(hours, hourlypay);
     
        if (overtimehours){
            payment += overtime(overtimehours, hourlypay);
            }
     
        printf ("For working %d hours this week, and %d hours overtime, this employee should be paid $%lg.",
                    hours, overtimehours, payment);
        return(0);
    }

  12. #12
    Registered User ortegac's Avatar
    Join Date
    Mar 2006
    Location
    In front of the computer screen
    Posts
    15

    Hey men you are good. Lets see if you can do this. Is more challenging

    The stuff i gave you to do is from my last semester in Junior college.
    But it seem you are pretty good. I think this will be more complicated this is what i have done in class this semester intermediate c programming.
    This problems was one of the hardest and it took some time for some of our classmates.

    Challenge your self and do this now

    Mr. C

    Code:
    We have been meddling with this ADT long enough:
    Before displaying the menu; check to see if the save file(named below) exists, and if it does, load in all records in the file.
    
    Create a main() function (and supporting functions) to allow the user to:
    
       1. add data to your list,
       2. delete data from your list,
       3. display the stored items,
       4. save data into a file [list.dat] in the same directory as the executable,
       5. load data from the above mentioned file, (note if this is done after edits and deletes it will "forget" all edits that have been done.)
       6. and finally quit (when the user wishes to smile )
    
    Compile and link all portions, and get the creature singing...

  13. #13
    Registered User
    Join Date
    Apr 2006
    Posts
    2
    Sorry for jumping in, but I've been looking for something like this for a while, because I want to learn C, but I've never been able to sit down and write little "learning" programs by myself, partly because it seems dumb to do that without feedback, to see if you've done something wrong, and partly because I've never been able to think of any <.<;;

    Anyway, here's what I've come up with for the payment problem:
    Code:
    #include <stdio.h>
    
    int main()
    {
    	int iHours = 0;
    	float fPayRate = 0.0;
    	float fTotalPay = 0.0;
    
    	puts("Please enter number of hours worked:");
    	scanf("%d", &iHours);
    
    	puts("Please enter hourly pay rate:");
    	scanf("%f", &fPayRate);
    
    	while(iHours > 0)
    	{
    		if(iHours > 40)
    			fTotalPay += (fPayRate * 1.5);
    		else
    			fTotalPay += fPayRate;
    
    		iHours--;
    	}
    
    	printf("The Employee earned $%.2f ", fTotalPay);
    	
    	return 0;
    
    }
    Also, I'd like to thank you for doing this. I've seen requests for _simple_ programming problems/ideas in many different forums and websites, but I think this is the first time I've ever seen someone reply with actual problems.

  14. #14
    Registered User ortegac's Avatar
    Join Date
    Mar 2006
    Location
    In front of the computer screen
    Posts
    15

    This was my answer for employee program

    Code:
    /*This program will calculate the employee pay for the week and overtime*/
    
    #include <stdio.h>
    
    
    main ()
    
    {
      float amnt, overtime;
      float a, b;
        
      printf(" ***Calculate your employees pay here for 40 hour normal working week and OT***\n\n");
      printf("What is the amount your employees earn for the hour:\n");
      scanf ("%f", &amnt);
      printf("Enter the amount of overtime hours the employee works:\n");
      scanf ("%f", &overtime); 
                  
      printf("\n\n\n $%2.2f per hour\n", amnt);
      printf("\n\n\n%2.0f hours in overtime\n\n", overtime);
                      
         a = 40.0 * amnt;
         b = (1.5 * overtime * amnt); 
                          
      printf("Your employee (40 hour) weekly pay is: $%3.2f\n\n", a);
      printf("*******************************************************\n\n");
      printf("Your employee overtime pay is: $%3.2f\n\n",b);
      printf("*******************************************************\n\n");
      printf("Your employee total pay incuding overtime is: $%3.2f\n\n", a + b);
                                    
                                      
         return 0;
                                      
    }
    Now try to do the other program i think you can ... hahaha

    See ya later

    Mr. C

  15. #15
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,161
    Mindphuck
    Could you make this piece of your code:
    Code:
    payment = weeklywage(hours, hourlypay);
    if (overtimehours)
    {
        payment += overtime(overtimehours, hourlypay);
    }
    as one single statement? And with no IF?

    Kyuubi
    Not quite.
    The hours up to 40 are at the regular rate.
    The hours beyond 40 are at the overtime rate.
    The loop for calculation is a really slow process. It's better to simply multiply rate * hours.

    ortegac
    What if they only work 30 hours?
    It's preferable to enter total hours worked and figure out the number of OT hours from one input.


    And in all cases, what if they work 35.5 hours? Or any partial hours? Food for thought...
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My bubble sort only sorts once
    By Muller in forum C Programming
    Replies: 8
    Last Post: 03-27-2009, 04:36 PM
  2. Simple Sorts Confuse ME =/
    By otchster in forum C Programming
    Replies: 5
    Last Post: 12-03-2005, 01:02 PM
  3. sorts
    By xddxogm3 in forum C++ Programming
    Replies: 5
    Last Post: 10-17-2004, 07:26 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 06:18 AM
  5. sorting of sorts....hehe
    By newbie2C++ in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2001, 12:02 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21