WiiLoaded.com - Wii Forum and News

Full Version: Help With C++
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Exactly what I changed Smile

cout << "Cosmic was right!" << endl;

TheCosmicFrog Wrote:
Exactly what I changed Smile

cout << "Cosmic was right!" << endl;


hmm, but you bloated the code I separating declaration and definition

Code:
#include <iostream>
using namespace std;

int main()
{
    double dn[2];
    
    cout << "please enter 3 numbers!\n";
    cin >> dn[0];
    cin >> dn[1];
    cin >> dn[2];
    cout << "the average of the numbers are: " << ((dn[0]+dn[1]+dn[2])/3) << "\n";
    
    cout << "Press enter to exit\n";
    cin.sync();
    cin.get();
    return 0;
}


that's much nicer code

Don't use SYSTEM('PAUSE') as it's not portable.
Don't use endl, because it's significantly slower than \n, plus it makes your source files smaller.
Arrays are the best thing to do when you're doing programs with lots of variables with the same type of information, because it adds flexibility.


and make sure you mess with the compiler settings.
you can sometimes half the size of an executable.

O.o my brain hurts. Umm for complete and utter 12 year old dummys, where do you recomend starting? I want to get into video game designing (which I"m pretty sure C++ is)

Code:
#include <iostream>
using namespace std;

double average(double dn[], int isize)
{
    double dsum = 0;
    for(int i=0;i<isize;i++)
    {
        dsum += dn[i];
    }
    return dsum/isize;
}

int main()
{
    int isize = 3;
    cout << "How many numbers do you want to average? ";
    cin >> isize;
    double dn[isize-1];

    for(int i=0;i<isize;i++)
    {
        cout << "Please enter number " << (i+1) << ": ";
        cin >> dn[i];
    }
    cout << "\n\nThe average of the numbers is: " << average(dn, isize) << "\n";
    
    cout << "\nPress enter to exit\n";
    cin.sync();
    cin.get();
    return 0;
}


Here's what I mean about arrays being more flexible

Toon324 Wrote:
O.o my brain hurts. Umm for complete and utter 12 year old dummys, where do you recomend starting? I want to get into video game designing (which I"m pretty sure C++ is)


C++ for dummies. Look around at your local bookstore.

_________________________________________________________

I actually followed this tutorial without no knowledge, I hadn't started reading. The tutorial was pretty bad, and blurred. That is why I put " instead of =.

Silly me. Toungue

Toon324 Wrote:
O.o my brain hurts. Umm for complete and utter 12 year old dummys, where do you recomend starting? I want to get into video game designing (which I"m pretty sure C++ is)


...




Good book, but really I'd leave it for a year or two. It's a complete mind bender in some places, but as Billy said once you read over each chapter a few times (which is recommended anyway) you'll, hopefully, get it.

Just be careful. Have a look at it first and if you feel you're not up for it, don't buy it. The book costs $26.

Even though the book I have is by Stephen Randy Davis:





Billy, which edition do you have? Mine is that one up there, the 5th edition.

Pages: 1 2
Reference URL's