![]() |
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! |
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 |
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;) // go a few more lines |
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 |
Quote:
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;} |
Q = amount / 25
amount %= 25 D = amount / 10 amount %= 10 N = amount / 5 P = amount % 5 No loops, and its not retarded. |
Ya, don't forget that loops come later. We did the same thing in the programming classes I had to take for chemical engineering.
|
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? |
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. |
IDK aboutyou but I love paying for classes that teach me bad habits like copypasta'ing something 9x
|
All times are GMT -4. The time now is 04:55 PM. |
Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.