Project 1999

Go Back   Project 1999 > General Community > Off Topic

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 04-21-2011, 11:45 PM
Jburks8 Jburks8 is offline
Kobold


Join Date: Sep 2010
Posts: 104
Default C++ Help

Any shot anyone could lend me any C ++ help for school? I'm not very computer savy. The projects are probably a piece of cake for anyone with even a little bit of C++ knowledge.

Here they are:

1). READ THE PROBLEM: Write a program to find the smallest number, the largest number, and the average of any five numbers entered by the user. For example, if the five numbers entered are 1, 2, 3, 4, and 5, the answers should be smallest =1, largest=5, and average=3. (Your program should handle any five numbers from 1 to 1,000, in any sequence entered.)


2). READ THE PROBLEM: Write a program to ask for any amount from 0 to 99. This is the amount of change to be made. The program should calculate the number of quarters, dimes, nickels, and pennies to make the specified change with the fewest coins possible. For example, if the amount is 92 then your program should have output similar to this: Q=3, D=1, N=1. P=2.


Thanks in advance for anyone who may be able to help or offer me any advice!
  #2  
Old 04-21-2011, 11:48 PM
naez naez is offline
Banned


Join Date: Mar 2011
Location: s0cal
Posts: 629
Send a message via ICQ to naez Send a message via AIM to naez Send a message via MSN to naez Send a message via Yahoo to naez
Default

Those are actually simple, but I am too lazy to help you. When I am too lazy to do something, I post it on www.stackoverflow.com. The nerds there have done like 90% of my programming since they existed.

Just don't say it's HW, make up something.


---

For the first one I'd like store the five numbers in an array, then run them through min() and max() and through a for loop to do the average.


---


For the second one define the value of coins, then take the input int and just go through them.

Code:
#define QUARTER 25

// then in main():

int numquarters = 0, numdimes = 0;

int i;
cin >> i;

while ( i != 0)
{
      if (i >= QUARTER)
      {
          i -= QUARTER;
          numquarters++;
          continue;
      }
     // dimes etc fall thru
}

printf("Q=%d, D=%d, ...", numquarters, numdimes, ...);
sry lazy
Last edited by naez; 04-22-2011 at 12:00 AM..
  #3  
Old 04-22-2011, 12:03 AM
Jburks8 Jburks8 is offline
Kobold


Join Date: Sep 2010
Posts: 104
Default

Awesome man, I'll try and post something there for sure. The help that I got from my instructor was this:

#include <iostream.h>

void main()

{int amount, Q, D, N, P;



Q=0; D=0; N=0; P=0;



cout << "Enter amount" << endl;

cin >> amount;

cout<<endl;


if (amount>24) {Q=Q+1; amount=amount-25;}

if (amount>24) {Q=Q+1; amount=amount-25;}

if (amount>24) {Q=Q+1; amount=amount-25;}

if (amount>9) {D=D+1; amount=amount-10[You must be logged in to view images. Log in or Register.]

// go a few more lines
  #4  
Old 04-22-2011, 12:04 AM
naez naez is offline
Banned


Join Date: Mar 2011
Location: s0cal
Posts: 629
Send a message via ICQ to naez Send a message via AIM to naez Send a message via MSN to naez Send a message via Yahoo to naez
Default

your instructor makes me want to strangle young children, thats the most noobish code I've ever seen out of someone with a degree in the subject

<iostream> not <iostream.h>, c'mon lets use standards
void main()
he declares QDNP, but then assigns them base value on a different line(s)
no use of overloaded operators like ++ or -=
what a lazy fuckng way to account if there is more than 2 quarters, whats he want 9 if statements for pennies? copypasta that totally violates D.R.Y.
srsly wtf



god this rages me
Last edited by naez; 04-22-2011 at 12:33 AM..
  #5  
Old 04-22-2011, 09:29 AM
moklianne moklianne is offline
Sarnak


Join Date: Dec 2010
Posts: 418
Default

Quote:
Originally Posted by naez [You must be logged in to view images. Log in or Register.]
your instructor makes me want to strangle young children, thats the most noobish code I've ever seen out of someone with a degree in the subject

<iostream> not <iostream.h>, c'mon lets use standards
void main()
he declares QDNP, but then assigns them base value on a different line(s)
no use of overloaded operators like ++ or -=
what a lazy fuckng way to account if there is more than 2 quarters, whats he want 9 if statements for pennies? copypasta that totally violates D.R.Y.
srsly wtf



god this rages me
What makes you think he has a degree in this? [You must be logged in to view images. Log in or Register.] All the programming instructers I've had at my college were all adjuncts with no relavent degree.
Plus, when teaching its easier to read this way for programming newbs. Besides, things get easier when they learn about for and while loops. I'm under the assumption that he hasn't introduced them yet because he gave them this:
Code:
if (amount>24) {Q=Q+1; amount=amount-25;}

if (amount>24) {Q=Q+1; amount=amount-25;}

if (amount>24) {Q=Q+1; amount=amount-25;}

if (amount>9) {D=D+1; amount=amount-10
  #6  
Old 04-22-2011, 09:39 AM
Ihealyou Ihealyou is offline
Sarnak

Ihealyou's Avatar

Join Date: Apr 2010
Location: Cleveland, OH
Posts: 454
Send a message via AIM to Ihealyou
Default

Q = amount / 25
amount %= 25
D = amount / 10
amount %= 10
N = amount / 5
P = amount % 5

No loops, and its not retarded.
__________________


Uuur - Your favorite Master +1 cleric <LifeAlert>
Rockwell - Your favorite 30 virgin <Aspen and Rockwell>
Last edited by Ihealyou; 04-22-2011 at 03:55 PM.. Reason: c++ lets you make dumb typos without giving an error
  #7  
Old 04-22-2011, 09:52 AM
bman8810 bman8810 is offline
Kobold


Join Date: Nov 2010
Posts: 149
Default

Ya, don't forget that loops come later. We did the same thing in the programming classes I had to take for chemical engineering.
  #8  
Old 04-22-2011, 10:00 AM
quido quido is offline
Planar Protector

quido's Avatar

Join Date: Oct 2009
Posts: 5,501
Default

Did they teach you how to define and use variables? How to accept input and generate output?

More importantly are you familiar with integer math on a computer and the concept of modulus? It's one thing to get a code snippet from some guy on a forum and it's another thing to understand what is happening here. I certainly hope you have received more instruction than just that one silly example program.

Have you tried to just do it yourself? Where are you running into problems?
__________________
Bush <Toxic>
Jeremy <TMO> - Patron Saint of Blue
  #9  
Old 04-22-2011, 10:25 AM
moklianne moklianne is offline
Sarnak


Join Date: Dec 2010
Posts: 418
Default

If loops haven't been taught yet, that code mentioned in post #2 won't work or at least will raise a question on whether you did it yourself or not.

If the instructer went over flowcharting, definitely do that. It helps.
Last edited by moklianne; 04-22-2011 at 10:27 AM..
  #10  
Old 04-22-2011, 02:19 PM
naez naez is offline
Banned


Join Date: Mar 2011
Location: s0cal
Posts: 629
Send a message via ICQ to naez Send a message via AIM to naez Send a message via MSN to naez Send a message via Yahoo to naez
Default

IDK aboutyou but I love paying for classes that teach me bad habits like copypasta'ing something 9x
Closed Thread


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:38 PM.


Everquest is a registered trademark of Daybreak Game Company LLC.
Project 1999 is not associated or affiliated in any way with Daybreak Game Company LLC.
Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.