Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → C++ help. My teacher does not teach =(
C++ help. My teacher does not teach =(
2004-12-26, 8:20 PM #1
Ive attached my assignment, so you know what i gotta do. bluntly put though, i learn programming my example because my teacher doesnt teach. and i do try reading books infact we have a c++ textbook type thing we use as a reference but im just kind of stupid about these things.it would mean somuch to me if someone could give me the basic code for that program, or even start me off..like im soconfused about the syntax and everything. i dont even know what the random integer function is like...and i mean the program is to generate bingo cards! and im not quite sure about arguments, i think i get what they are still kind of lost. or how to call arguments through main thatt totally blows my mind. at school we're using MSvisual c++ but since they havent bought the compiler (the school board) for student use, at home we are jsut to download a rnadom compiler that resembles it. so i got this thing by bloodshed.com i think it is, called Dev-C++. if anyone could jus do the program for me half assed even n maybe comment n explain it to me i could make my own :( bleh if any of you know me, this isnt me tryin to get other peole to do my work. im so stressed. i remember when i actually enjoyed programming.
[teletubbie voice] BIG HUG!!!! [/teletubbie voice]
2004-12-26, 8:30 PM #2
Google is your friend. Randomization is quite easy.

Java > C++ (well, if you consider C++ to be damn cryptic in comparison)
2004-12-26, 8:40 PM #3
Teachers not teaching computer science...gee doesn't that sound familiar. :p

For starters your randomization function is rand() and it is used in this manner.

Code:
#include <time.h>

srand((unsigned int)time(NULL)); //Seed your randomizer
unsigned int GetRandom(int lower, int upper)
{
    unsigned int randNum=(rand()*lower) % upper;
    return randNum;
}

Someone do correct me on the code. It's been a while since I've used the rand(). But I think it's in that form.

If I understand correctly. This is how you would do it.
Code:
unsigned int B[5];
unsigned int I[5];
unsigned int N[5];
unsigned int G[5];
unsigned int O[5]; //Remember arrays are 0-based

//Fill B (using above function)
for (unsigned int i=0; i<5; i++)
    B=GetRandom(0,15);

You would just do the same for loops for the rest of the arrays.

This good?

Edit: Darth wins by a lot.
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2004-12-26, 8:50 PM #4
When you declare the arrays, they should be [5], not [4]. Although they are zero based, it needs to be five because the last section of the array holds a terminating character.

Also, you have to run through th array each time you generate an int, since you have to check for duplicates. I suggest setting all the array values to zero, then just comparing a random int to all the numbers in its column to make sure there are no duplicates.
[This message has been edited. Deal with it.]
2004-12-26, 8:52 PM #5
Quote:
Originally posted by Malus
When you declare the arrays, they should be [5], not [4]. Although they are zero based, it needs to be five because the last section of the array holds a terminating character.

It's not a character string. Why would there need to be a terminating CHARacter for an array of INTegers?
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2004-12-26, 9:00 PM #6
When you're declaring the static array, you're giving it the size in the brackets, so it's not zero-based. The size is still 5, with indexes from 0 to 4.

Curious, is this a high school class? Just wandering since high school programming classes are mostly just teachers who know how to read trying to teach purely from a book. College ones are much better because most of the time you get a professor who knows what they're doing.
2004-12-26, 9:01 PM #7
Yours would work, JediG, except that the assignment screws it up by requiring that N(2) = "**". Just declare N(3) as integers and after you print n(1), print "**" and move on to n(2).
2004-12-26, 9:26 PM #8
Quote:
Originally posted by JediGandalf
It's not a character string. Why would there need to be a terminating CHARacter for an array of INTegers?


Ah, silly me.
[This message has been edited. Deal with it.]
2004-12-26, 9:44 PM #9
By the way, this needs to be moved to the Tech Forum. Wolvie is no acception to the rules, espcially when we are doing her homework.


Ya JG, you were correct about how to use the rand() function.
Whenever you have a limit for the highest number that can be produced by the ran function, you have to do rand() % upper limit.

Darth: College level C/C++ classes don't get that much better. Most teachers, yes, know what they are doing, but doesn't mean that like to teach ;). It often shows whether they like to or not.
In Tribute to Adam Sliger. Rest in Peace

10/7/85 - 12/9/03
2004-12-26, 11:53 PM #10
Wow, this reminds me of my C++ class. Honestly, that class taught me nothing. And C++ simply seems silly to me now, what with all the splended coding languages we have now.

JediKirby
ᵗʰᵉᵇˢᵍ๒ᵍᵐᵃᶥᶫ∙ᶜᵒᵐ
ᴸᶥᵛᵉ ᴼᵑ ᴬᵈᵃᵐ
2004-12-27, 12:26 AM #11
There aren't a whole lot of mainstream languages newer than C++. Sure, Java and C#, but what else could you possibly be referring to?
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2004-12-27, 12:33 AM #12
Quote:
Originally posted by Freelancer
There aren't a whole lot of mainstream languages newer than C++. Sure, Java and C#, but what else could you possibly be referring to?

PHP for one. Ruby is another. Javascript. Uhh...Visual Basic I guess. It's a lot more that the original Basic.

None of those stack up to C++ though. PHP is the runner up. OOP, inheritance, polymorphism. PHP can inherit but not do polymorphism. And believe me polymorphism is a GOOD THING.

Oh and Kirby, if you are referring to ALL modern (splendid) programming languages, the select ones mentioned are pretty much it. For PLs just for standalone applications, Java...that's it. And it's SLOW. Perl is as old as C++. Python isn't much newer. Delphi is one of the older models.

C++ is the way to go for application writing.
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2004-12-27, 12:37 AM #13
Eh.. I don't see too many standalone applications written in PHP, Ruby, and Javascript. And visual basic? A splendid language? Baahahah. I agree with you, though. C++ rocks. Though I really do prefer Java. If Java wasn't so damn slow I'd use it exclusively.
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2004-12-27, 12:45 AM #14
Quote:
Originally posted by jEDIkIRBY
Wow, this reminds me of my C++ class. Honestly, that class taught me nothing. And C++ simply seems silly to me now, what with all the splended coding languages we have now.

JediKirby


wtf... my only advice with C++ is just stick with it... it's not easy at first but you should get it after a bit then it will be just like a second tounge to you.
2004-12-27, 12:58 AM #15
unsigned int GetRandom(int lower, int upper)
{
unsigned int randNum=(rand()*lower) % upper;
return randNum;
}

should be

unsigned int GetRandom(int lower, int upper)
{
unsigned int randNum=rand() % (upper - lower) + lower;
return randNum;
}

otherwise it will only generate numbers in multiples of the lower bounds, and also not inside the [lower, upper) range
Air Master 3D (my iPhone game)
My Programming Website
2004-12-27, 5:17 AM #16
Quote:
Originally posted by Freelancer
And visual basic? A splendid language? Baahahah.


While limiting in some ways, VB opens up a world of options if you just came off QBasic. :p Not to mention using API calls, VB programs can be just as powerful/complicated as VC++ ones.

Anyway, Wolvie, your teacher sucks. My programming teacher in HS was a guy who liked programming. :)
-Hell Raiser
2004-12-27, 9:28 AM #17
thanks guys! sorry for posting on the wrong forum :( people always kind of post their hw on general so i thought tahts where we were sposed to.

Ps. yeah darth, grade 12 programming.
[teletubbie voice] BIG HUG!!!! [/teletubbie voice]
2004-12-27, 10:34 AM #18
Wolvie, I still love you.
In Tribute to Adam Sliger. Rest in Peace

10/7/85 - 12/9/03
2004-12-27, 10:42 AM #19
I took ICS 4MI last year... they taught us Java though. I got lucky and got a teacher that was a really good programmer.
That painting was a gift, Todd. I'm taking it with me.
2004-12-27, 11:00 AM #20
the help made sense until i tried workin with the code and..well i failed miserably. i can recognize structures in code but im so lost sometimes i just dont get whats part of the syntax and whats not. bleh.
[teletubbie voice] BIG HUG!!!! [/teletubbie voice]
2004-12-27, 11:28 AM #21
Quote:
Originally posted by Wolvie17
the help made sense until i tried workin with the code and..well i failed miserably. i can recognize structures in code but im so lost sometimes i just dont get whats part of the syntax and whats not. bleh.

With what part of the code are you having a hard time?
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2004-12-27, 1:39 PM #22
i dont think anyone realizes how much i dont get any of it :(. like just using it in my program. i dont know when to and when not to use main. im not even sure what main is for. whats void? where do i put functions into my program, before or in between the main/void braces? so lost.
[teletubbie voice] BIG HUG!!!! [/teletubbie voice]
2004-12-27, 1:44 PM #23
You ALWAYS have to use main(). The instructions inside the main curly braces is what gets executed when the program is run.

Void just means that either:
1. The function doesn't return anything:
void SomeFunction(int SomeNumber, string SomeText)

2. The function doesn't require any parameters.
int SomeFunction(void)

The functions should be placed before or after main(), never inside. The best thing to do, to keep your code readable, is to place your function prototype before main, and the function code after.

Such as:
Code:
#include <iostream>
#include <time.h>

using namespace std;

unsigned int GetRandom(int lower, int upper); // Prototype

int main(void)
{
     // Program instructions
}

// Here's the function, after main()
unsigned int GetRandom(int lower, int upper)
{
    unsigned int randNum=(rand()*lower) % upper;
    return randNum;
}
2004-12-27, 1:48 PM #24
You ALWAYS use main() in your program. It is like the function. Where you place it in what source file is up to you but you must have a main function.

"void" is a datatype much like int, char, float, long, double, etc. The "void" in front of the function declaration means that the function returns nothing. If you had int or char in front of the function declaration, it means you are returning a value of the same datatype

int main() - Somewhere in your function you must use "return"

void my_func() - this function doesn't return anything.

Placement of functions usually comes before main. Personally, I place functions ahead of main(). This way I do not have to prototype.

And what Shintock said above is good. He can just type faster. :P
Code to the left of him, code to the right of him, code in front of him compil'd and thundered. Programm'd at with shot and $SHELL. Boldly he typed and well. Into the jaws of C. Into the mouth of PERL. Debug'd the 0x258.
2004-12-27, 1:57 PM #25
And if you're still confused about returning stuff, you use the return keyword to cause the function to spit back a value when you call it. Like this:

int add (int x, int y) {
return x+y;
}

Then if you call it, you can go like this:

cout << add(4,6); //print 10 to the console
int someNumber = add(9,6); // since this function returns something, you can assign what it returns to a variable. In this case, someNumber will be 15.

If you had a void function, like this:

void doSomething() {
cout << "Do something.";
}

And you tried to assign it to a variable, like this:

int num = doSomething();

You'll get a compiler error.
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2004-12-27, 2:09 PM #26
Oh my god, C++ looks horribly complicated, and this is the thing I want to learn when I'm older??? Hell no. :eek:
Sneaky sneaks. I'm actually a werewolf. Woof.
2004-12-27, 2:17 PM #27
oh my goodness that helped explain that so well! ty so much JG, freelancer + shintock. its coming together now slowly in my head :P the C++ atleast :) TY guys *hugs for everyone*
[teletubbie voice] BIG HUG!!!! [/teletubbie voice]
2004-12-27, 4:00 PM #28
Quote:
Originally posted by Oxyonagon
Oh my god, C++ looks horribly complicated, and this is the thing I want to learn when I'm older??? Hell no. :eek:
It's not too bad, and it's something you're going to need to know if you want to go into the gaming industry. There's an order to it, somewhere.
2004-12-27, 4:02 PM #29
Quote:
Originally posted by Wolvie17
*hugs for everyone*

That's the closest to first base most Massassians are ever going to get.
2004-12-27, 7:04 PM #30
Quote:
Originally posted by Oxyonagon
Oh my god, C++ looks horribly complicated, and this is the thing I want to learn when I'm older??? Hell no. :eek:


It's only intimidating until you learn how to do it. Trust me.
D E A T H
2004-12-28, 4:40 AM #31
It's not even intimidating. It's learning a new language in order to talk to the computer so it can understand what you want it to do. :D Just like Spanish, or French, a programming language is no different. There's syntax (grammar) and logic layout (a proper and optimized order to speak in) so it understands you better. Don't wanna tell the computer "You thing good make look" when you mean "Texture this SOB" ;)
-Hell Raiser

↑ Up to the top!