[C++] My first Program with no tut ;d

Results 1 to 7 of 7
  1. #1
    offonline King Grub is offline
    MemberRank
    Aug 2009 Join Date
    Spring fieldLocation
    3,303Posts

    [C++] My first Program with no tut ;d

    Hah!

    As title say.

    First i made a basic with x + y
    Then i improved it by adding 6 numbers
    After that i tried to make a (Negative number) Worked:D
    Then i added so it shows the sum everytime you've added new numbers.

    PHP Code:
    #include <iostream>

    int main() {
     
        
    int x;
        
    int y;
        
    int z;
        
    int a;
        
    int b;
        
    int w;

        
    using namespace std;

        
    cout << " This counter is made by Charlie & The first 5 numebers are posetive addition and the last is negative. Enjoy! \n \n \n ";

        
    cout << " Enter a number: ";
        
    cin >> x;
        
    cout << " \n The current sum is: " << <<endl;

        
    cout << " Enter a second number: ";
        
    cin >> y;
        
    cout << " \n The current sum is: " << <<endl;

        
    cout << " Enter a third number: ";
        
    cin >> z;
        
    cout << " \n The current sum is: " << <<endl;

        
    cout << " Enter a fourth number: ";
        
    cin >> a;
        
    cout << " \n The current sum is: " << <<endl;
        
        
    cout << " Enter a fifth number: ";
        
    cin >> b;
        
    cout << " \n The current sum is: " << b<<endl;

        
    cout << " Enter a last negative number: ";
        
    cin >> w;
        
    cout << " \n The current sum is: " << w<<endl;

        
    cout << " The sum of all these numbers togheter is: " << <<endl;
        
    cin.get();
        
    cin.ignore();
        return 
    0;



  2. #2
    Watching from above Negata is offline
    LegendRank
    Apr 2004 Join Date
    FinlandLocation
    5,455Posts

    Re: [C++] My first Program with no tut ;d

    Next step and huge improvement: loop & array.

  3. #3
    offonline King Grub is offline
    MemberRank
    Aug 2009 Join Date
    Spring fieldLocation
    3,303Posts

    Re: [C++] My first Program with no tut ;d

    Quote Originally Posted by Negata View Post
    Next step and huge improvement: loop & array.
    Probaly.

  4. #4
    Account Upgraded | Title Enabled! X-Tasis is offline
    MemberRank
    Feb 2009 Join Date
    1,192Posts

    Re: [C++] My first Program with no tut ;d

    cout << " Enter a last negative number: ";
    cin >> w;
    cout << " \n The current sum is: " << x + y + z + a + b - w<<endl;

    this is not right.it must be + w

  5. #5
    Infraction Baɴɴed holthelper is offline
    MemberRank
    Apr 2008 Join Date
    1,765Posts

    Re: [C++] My first Program with no tut ;d

    Quote Originally Posted by X-Tasis View Post
    cout << " Enter a last negative number: ";
    cin >> w;
    cout << " \n The current sum is: " << x + y + z + a + b - w<<endl;

    this is not right.it must be + w
    i think he made it so that the last number is a negative to counter the - w part.

    EDIT:
    yea that was what he was trying to do.

    proof: "Enter a last negative number:"

  6. #6
    Account Upgraded | Title Enabled! jakesdexless is offline
    MemberRank
    Nov 2008 Join Date
    278Posts

    Re: [C++] My first Program with no tut ;d

    Quote Originally Posted by holthelper View Post
    i think he made it so that the last number is a negative to counter the - w part.

    EDIT:
    yea that was what he was trying to do.

    proof: "Enter a last negative number:"
    it never said add up the absolute values, it is add up all the numbers. example:
    1+2+3+4=10
    1+2+3+4-5 is not 15, but that's what you would get
    PHP Code:
    #include<iostream>

    int main() {
        
    int num 1;
        
    int currentsum 0;
        
    int numwanted;
        
    cout << "How many numbers do you want to add up?";
        
    cin >> numwanted;
        for (
    int i =0numwantedi++) {
        
    cout << "\nEnter number " num;
        
    cin >> x;
        
    currentsum += x;
        
    cout << " \n The current sum is: " << currentsum
        }
        return 
    0;

    not the best way to do it, but it's an improvement

  7. #7
    Account Upgraded | Title Enabled! c4cadvisor is offline
    MemberRank
    Aug 2008 Join Date
    mmorpgexplosionLocation
    628Posts

    Re: [C++] My first Program with no tut ;d

    who says you need the "best" way to do it? As long as you know it works it is fine, then step up to optimize the code. BTW, congrats on your first program without a tutorial.



Advertisement