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: 116
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: 116
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, 02:52 PM
Rogean Rogean is offline
¯\_(ツ)_/¯

Rogean's Avatar

Join Date: Oct 2009
Location: Massachusetts
Posts: 5,390
Default

Quote:
Originally Posted by Ihealyou [You must be logged in to view images. Log in or Register.]
amount &= 25
amount &= 10
You mean %= ?

&= is bitwise assignment.
__________________
Sean "Rogean" Norton
Project 1999 Co-Manager

Project 1999 Setup Guide
  #8  
Old 04-22-2011, 03:53 PM
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

Quote:
Originally Posted by Rogean [You must be logged in to view images. Log in or Register.]
You mean %= ?

&= is bitwise assignment.
Lol, I didn't even realize I wrote &= until you said that. In my defense, it was on my phone and % and & are both tall and squiggly, so they're basically the same thing anyways.
__________________


Uuur - Your favorite Master +1 cleric <LifeAlert>
Rockwell - Your favorite 30 virgin <Aspen and Rockwell>
  #9  
Old 04-25-2011, 01:01 PM
Rogean Rogean is offline
¯\_(ツ)_/¯

Rogean's Avatar

Join Date: Oct 2009
Location: Massachusetts
Posts: 5,390
Default

Quote:
Originally Posted by Ihealyou [You must be logged in to view images. Log in or Register.]
Lol, I didn't even realize I wrote &= until you said that. In my defense, it was on my phone and % and & are both tall and squiggly, so they're basically the same thing anyways.
Under normal circumstances I'd agree.. but it's typos just like that that make you spend a fucking hour trying to figure out why your program isn't working correctly, debugging the shit out of it... and then it hits you in the face like a brick and you proceed to facepalm for 5 minutes.

Too many times that happens to me. Infact I spent over an hour just last night trying to figure out why some code was acting wonky and its because I did a delete on a char pointer instead of delete[], in a completely different function.
__________________
Sean "Rogean" Norton
Project 1999 Co-Manager

Project 1999 Setup Guide
  #10  
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.
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 02:43 AM.


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 - 2025, Jelsoft Enterprises Ltd.