PDA

View Full Version : BEHOLD MY GREATNESS! (first complicated c++ program)



Cap'n 1time
September 12th, 2007, 22:17
I have been taking a c++ class for about 2 weeks. Ive done some silly little things using the standard cpp libraries but nothing really complexed.

Anyone whos taken a programming class will probably be familiar with this one. It is the Fibonacci program where you determine the nth number of the sequence. Mine has a slight twist however. The book wants me to use the sequence to determine how asexual things reproduce. In other words... basically you just multiply the initial value by the "final sum" which is actually just the place in the fibonacci sequence you determined.

BEHOLD MY CODE!
---------------------------

//Greatest program in the world.
//By: Alan Gardner

#include <iostream>
using namespace std;

int main()
{
int count;
// long long is HUGE! alast and blast are initialized.
long long alast, blast, sum, n;
int totamnt;
alast = 0;
blast = 1;
// Determines place in the sequence.
cout << "Enter time: ";
cin >> n;
cout << "\n";
// Determines inital amount (what to multiply final sum by).
cout << "Enter total amount: ";
cin >> totamnt;
cout << "\n";
switch (n)
{
// Catches 0 before it outputs a negative number.
case 0: cout << "0"; break;
// Catches 1 before it outputs 0.
case 1: cout << 1 * totamnt; break;
default:
// Determines place in the sequence.
for (count= 0; count < n-1; count++)
{
// "Rolls" numbers around to make the sequece work.
sum = alast + blast;
alast = blast;
blast = sum;
};
// Outputs the place in the sequence multiplied by the initial ammount.
cout << "\n" << sum * totamnt << " is the total amount."; break;
}
return 0;
}

-----
Since there are no extra libraries, you should be able to just compile right away.

wolfpack
September 12th, 2007, 22:47
i tried running this on DarkBasic... didnt work... oh well, sorry i cant see your greatness banhammer!

splodger15
September 12th, 2007, 22:59
Nice work Capn 1 Time

Safari Al
September 12th, 2007, 23:09
wow i need to take a course to help me learn c. (Even though i know nothing about it lol)

Congrats Cap'n 1 time

SnesR0X
September 12th, 2007, 23:12
lol, I only know html

Cap'n 1time
September 12th, 2007, 23:15
i tried running this on DarkBasic... didnt work... oh well, sorry i cant see your greatness banhammer!

I dont know about darkbasic, but im pretty sure it wont compile c++. I've never used it, but Dev c++ is supposed to make the compilation process easy for windows.

try this. (http://sourceforge.net/project/showfiles.php?group_id=10639)



wow i need to take a course to help me learn c. (Even though i know nothing about it lol)


I highly recommend you take a beginners programming logic class before you take any computer languages. Without that class last semester I would be lost. Some people are able to pick the logic up right away... but I was not one of them.

the cplusplus.com website offers some good tutorials. Also keep in mind that C and C++ are similar, but are not the same.

mcdougall57
September 13th, 2007, 00:08
if you really wanna be up to date id recommend you take c#

Cap'n 1time
September 13th, 2007, 02:53
if you really wanna be up to date id recommend you take c#

Thats silly. everything that I want and need to do can be done in C++ or C. The work place (generally) does not give a rats ass what language I use so long as I get the work done (though they usually demand a C derivative it seems). I know a few coders in these forums who would gladly burn you at the stake for saying such things.

Some people would actually argue that I'd be better off primarily using C rather than C++ while others would just say to code in whatever I am most comfortable in. New is not always better.

DarthPaul
September 13th, 2007, 03:35
Wow! You actually coded something in C++ !!
Impossible! That's something out of this world ! You deserve a trophy! http://ngdek.ludost.net/forum/Smileys/classic/bored.gif

Tetris999
September 13th, 2007, 03:54
im taking ms dos then moving on to visual basic c++, who knows? i might make an app for the psp that uses the computer someday

BTW i only got as far as inputing co ordinates and making lines and playing music in MS DOS and also using the loop command lots

NoQuarter
September 13th, 2007, 04:26
So, are you gonna compile it for the psp?

shadowprophet
September 13th, 2007, 05:26
I have been taking a c++ class for about 2 weeks. Ive done some silly little things using the standard cpp libraries but nothing really complexed.

Anyone whos taken a programming class will probably be familiar with this one. It is the Fibonacci program where you determine the nth number of the sequence. Mine has a slight twist however. The book wants me to use the sequence to determine how asexual things reproduce. In other words... basically you just multiply the initial value by the "final sum" which is actually just the place in the fibonacci sequence you determined.

BEHOLD MY CODE!
---------------------------

//Greatest program in the world.
//By: Alan Gardner

#include <iostream>
using namespace std;

int main()
{
int count;
// long long is HUGE! alast and blast are initialized.
long long alast, blast, sum, n;
int totamnt;
alast = 0;
blast = 1;
// Determines place in the sequence.
cout << "Enter time: ";
cin >> n;
cout << "\n";
// Determines inital amount (what to multiply final sum by).
cout << "Enter total amount: ";
cin >> totamnt;
cout << "\n";
switch (n)
{
// Catches 0 before it outputs a negative number.
case 0: cout << "0"; break;
// Catches 1 before it outputs 0.
case 1: cout << 1 * totamnt; break;
default:
// Determines place in the sequence.
for (count= 0; count < n-1; count++)
{
// "Rolls" numbers around to make the sequece work.
sum = alast + blast;
alast = blast;
blast = sum;
};
// Outputs the place in the sequence multiplied by the initial ammount.
cout << "\n" << sum * totamnt << " is the total amount."; break;
}
return 0;
}

-----
Since there are no extra libraries, you should be able to just compile right away.

Sweet :cool:

It sure took you long enough we where talking about this stuff almost a year ago 1x :p Still your doing great, Ive all But given up codeing :o

Cap'n 1time
September 13th, 2007, 06:20
look at me being a dick!

So do you say that about all the homebrew coded in c++? The games? Your operating system? This a beginning step for me and I'm quite proud of it. If you dont have anything valuable to add (such as praise for my greatness) or any advice than please... dont comment.


So, are you gonna compile it for the psp?

somehow i dont think anyone will be interested in finding a value in the Fibonacci sequence on the go. :p



Sweet

It sure took you long enough we where talking about this stuff almost a year ago 1x Still your doing great, Ive all But given up codeing


I learned visual basic last year which was fairly simple. This is my first experience with a REAL programming language.

NoQuarter
September 13th, 2007, 06:25
Lol,I meant compile it for the psp for yourself as an exercise or fun.Didn't really mean for anybody else but you :)

shadowprophet
September 13th, 2007, 06:25
So do you say that about all the homebrew coded in c++? The games? Your operating system? This a beginning step for me and I'm quite proud of it. If you dont have anything valuable to add (such as praise for my greatness) or any advice than please... dont comment.



somehow i dont think anyone will be interested in finding a value in the Fibonacci sequence on the go. :p



I learned visual basic last year which was fairly simple. This is my first experience with a REAL programming language.
I was certain I was talking to you about c++ back then.

I must be getting old my mind is sliping.

NoQuarter
September 13th, 2007, 06:28
Either way congrats on your first real deal!
Why for do you give up on programming shadowprophet?

shadowprophet
September 13th, 2007, 06:32
Either way congrats on your first real deal!
Why for do you give up on programming shadowprophet?

Well it wasnt really like giving up, at first it was kinda like a challenge to me.
But once I began to understand it. And comprehend how it works, It was kind of like I solved the puzzle, And I kinda moved on after that

I can't resist a challenge:o

NoQuarter
September 13th, 2007, 06:37
Right on,honestly I can understand that sentiment.Personally I'm just a bit OCD once I start,only prob with programming is that I haven't really started.I'm such a procrastinator(1 year's worth).

I think I'm gonna bear down and really learn some stuff on this cycle though.

Cap'n 1time
September 13th, 2007, 08:47
Well it wasnt really like giving up, at first it was kinda like a challenge to me.
But once I began to understand it. And comprehend how it works, It was kind of like I solved the puzzle, And I kinda moved on after that

I can't resist a challenge:o

There is a lot more to c++ than just the standard libraries. There is plenty of challenge left for you.

parkermauney
September 13th, 2007, 23:03
stdio for life!