C++ Question

XZGohanXZGohan Scottsdale, Arizona Member
edited July 2003 in Science & Tech
ok...
code:
...
cout<<"Ranged Level ";
cin>>rangedlevel;
rangedlimit = (attacklevel + strengthlevel) / 1.475;
rangedpurity = rangedlevel - rangedlimit; //if negative = 0
rangedamount = 0>rangedpurity ? 0 : rangedpurity;
combatlevel = ((attacklevel + defenselevel + strengthlevel + hitpointslevel) / 4) + ((magiclevel + prayerlevel + rangedamount) / 8);
...


Im trying to make prayerlevel = 0 if it is below 0, negative, if its above 0 it will make itself to be that number.
That above is my lame attempt at doing something like it, however it doesnt work, of course :p
Wtf am I doing wrong? lol. I hate being a noob at things. :o

Thanks. :)

Comments

  • ktulu_tcoktulu_tco Akita, Japan
    edited June 2003
    I don't see where you define prayerlevel... I mean, your code says that rangedamount shouldn't be negative... where did you instantiate prayerlevel (can we see that code?)
  • XZGohanXZGohan Scottsdale, Arizona Member
    edited June 2003
    If you want the whole program, here :P
    #include <iostream.h>
    int main()
    {
      int chooser;
      cout<<"[---------------------------------------------beta.02-]\n";
      cout<<"[               >>Runescape Calculator<<              ]\n";
      cout<<"[  Instructions: Type the number of the calculator    ]\n";
      cout<<"[  want to use, then hit [enter].                     ]\n";
      cout<<"[                                                     ]\n";
      cout<<"[               1. Max Weapon Hit                     ]\n";
      cout<<"[               2. Max Ranged Hit                     ]\n";
      cout<<"[               3. Max Ranged Level                   ]\n";
      cout<<"[               4. Hit Points Level                   ]\n";
      cout<<"[               5. Combat Level                       ]\n";
      cout<<"[                                                     ]\n";
      cout<<"[-----------------------------------------------ch!bo-]\n";
      cout<<"Choose: ";
      cin>>chooser;
      if(chooser==1)
      {
        int strengthlvl;
        int weaponpow;
        int weaponhit;
        int bos;
        int ss;
        int us;
        cout<<"[---------------------------------------------beta.02-]\n";
        cout<<"[               >>Max Weapon Hit<<                    ]\n";
        cout<<"[  Instructions: Type in your strength and weapon     ]\n";
        cout<<"[  power and hit [enter].                             ]\n";
        cout<<"[                                                     ]\n";
        cout<<"[-----------------------------------------------ch!bo-]\n";
        cout<<"Strength Level: ";
        cin>>strengthlvl;
        cout<<"Weapon Power: ";
        cin>>weaponpow;
        weaponhit = (strengthlvl + weaponpow + 3) / 8.5;
        bos = ((strengthlvl + weaponpow + 3) * 1.05) / 8.5;
        ss = ((strengthlvl + weaponpow + 3) * 1.10) / 8.5;
        us = ((strengthlvl + weaponpow + 3) * 1.15) / 8.5;
        cout<<"\n";
        cout<<"You can hit "<<weaponhit; cout<<" naturally. \n";
        cout<<"You can hit "<<bos; cout<<" with Burst of Strength. \n";
        cout<<"You can hit "<<ss; cout<<" with Superhuman Strength. \n";
        cout<<"You can hit "<<us; cout<<" with Ultimate Strength. \n";
        cin.get();
      }
      if(chooser==2)
      {
        int rangedlevel;
        int arrowtype;
        int arrowhit;
        cout<<"[---------------------------------------------beta.02-]\n";
        cout<<"[             >>Max Ranged Hit<<                      ]\n";
        cout<<"[ Instructions:  Simply input your ranged level and   ]\n";
        cout<<"[ the arrows you will shoot with.                     ]\n";
        cout<<"[                                                     ]\n";
        cout<<"[ Arrow Codes:                                        ]\n";
        cout<<"[  1. Bronze Arrows                                   ]\n";
        cout<<"[  2. Iron Arrows                                     ]\n";
        cout<<"[  3. Steel Arrows                                    ]\n";
        cout<<"[  4. Mithril Arrows                                  ]\n";
        cout<<"[  5. Adamantite Arrows                               ]\n";
        cout<<"[  6. Runite Arrows                                   ]\n";
        cout<<"[                                                     ]\n";
        cout<<"[-----------------------------------------------ch!bo-]\n";
        cout<<"Ranged Level: ";
        cin>>rangedlevel;
        cout<<"Type of Arrows: ";
        cin>>arrowtype;
        arrowhit = (rangedlevel / 3) + arrowtype; //FIND THE RIGHT ONE FIND THE RIGHT ONE//FIND THE RIGHT ONE//FIND THE RIGHT ONE//FIND THE RIGHT ONE
        cout<<"You can hit "<<arrowhit; cout<<" with arrows. \n";
        cin.get();
      }
      if(chooser==3)
      {
        int strengthlevel;
        int attacklevel;
        int rangedlevel;
        cout<<"[---------------------------------------------beta.02-]\n";
        cout<<"[             >>Max Ranged Level<<                    ]\n";
        cout<<"[  Instructions:  Just input your strength and        ]\n";
        cout<<"[  attack levels, and the program will do the rest.   ]\n";
        cout<<"[                                                     ]\n";
        cout<<"[-----------------------------------------------ch!bo-]\n";
        cout<<"Strength Level: ";
        cin>>strengthlevel;
        cout<<"Attack Level: ";
        cin>>attacklevel;
        rangedlevel = (attacklevel + strengthlevel) / 1.475;
        cout<<"You may raise your ranged level to "<<rangedlevel; cout<<" while keeping your purity.";
        cin.get();
      }
      if(chooser==4)
      {
      //Find out how to get hitpoints level.
      }
      if(chooser==5)
      {
        int attacklevel;
        int defenselevel;
        int strengthlevel;
        int hitpointslevel;
        int rangedlevel;
        int magiclevel;
        int prayerlevel;
        int combatlevel;
        int purity;
        int primary;
        int secondary;
        int rangedlimit;
        int rangedpurity;
        int rangedamount;
        cout<<"[---------------------------------------------beta.02-]\n";
        cout<<"[             >>Combat Level<<                        ]\n";
        cout<<"[  Instructions: Input your attack, defense,          ]\n";
        cout<<"[  strength, hitpoints, ranged, magic, and prayer     ]\n";
        cout<<"[  levels to receive your combat level.               ]\n";
        cout<<"[                                                     ]\n";
        cout<<"[  Primary Levels: Attack, Defense, Strength, Hits    ]\n";
        cout<<"[  Secondary Levels: Magic, Prayer                    ]\n";
        cout<<"[    Note: Ranged affects combat if over the          ]\n";
        cout<<"[    level supplied by the calculator. It is a        ]\n";
        cout<<"[    secondary level.                                 ]\n";
        cout<<"[                                                     ]\n";
        cout<<"[-----------------------------------------------ch!bo-]\n";
        cout<<"Attack Level: ";
        cin>>attacklevel;
        cout<<"Defense Level: ";
        cin>>defenselevel;
        cout<<"Strength Level: ";
        cin>>strengthlevel;
        cout<<"Hitpoints Level: ";
        cin>>hitpointslevel;
        cout<<"Ranged Level: ";
        cin>>rangedlevel;
        cout<<"Magic Level: ";
        cin>>magiclevel;
        cout<<"Prayer Level: ";
        cin>>prayerlevel;
        rangedlimit = (attacklevel + strengthlevel) / 1.475;
        rangedpurity = rangedlevel - rangedlimit;
        rangedamount = 0>rangedpurity ? 0 : rangedpurity;
        combatlevel = ((attacklevel + defenselevel + strengthlevel + hitpointslevel) / 4) + ((magiclevel + prayerlevel + rangedamount) / 8);
        primary = ((combatlevel + 1) * 4) - ((attacklevel + defenselevel + strengthlevel + hitpointslevel) / 4);
        secondary = ((combatlevel + 1) * 8) -((prayerlevel + magiclevel) * 8);
        cout<<"\n";
        cout<<"You are: \n";
        cout<<"Combat Level: " <<combatlevel; cout<<"\n";
        cout<<"Percent Pure: " <<purity; cout<<"\n";
        cout<<"Primary Levels Left: " <<primary; cout<<"\n";
        cout<<"Secondary Levels Left: " <<secondary; cout<<"\n";
        cout<<"Ranged Will Affect At: " <<rangedlimit; cout<<"\n";
        cin.get();
      }
    }
    
    It gets cut off if I make it one code box...

    Also, for the life of me, I cannot figure out why primary/secondary are working right. o_O
  • edited June 2003
    okay i haven't program in c++ for a long time but i program c like everyday, so here i go with my first solution:

    make int prayerlevel if you have declare it an unsigned int prayerlevel which makes go to 0 to 65535.

    here is my second solution but it has more code:

    if (prayerlevel < 0 )
    {prayerlevel = 0;}

    I hope that helps (and works)!
  • XZGohanXZGohan Scottsdale, Arizona Member
    edited June 2003
    Ive been going for ranged level, so I guess I will try this...
    cout<<"Ranged Level: ";
    cin>>rangedlevel;
    rangedlimit = (attacklevel + strengthlevel) / 1.475;
    rangedpurity = rangedlevel - rangedlimit;
    if (rangedpurity < 0)
    {
    rangedamount = 0;
    }
    else if (rangedpurity > 0)
    {
    rangedamount = rangedpurity;
    }
    

    Thanks Tropical :D
  • a2jfreaka2jfreak Houston, TX Member
    edited July 2003
    What tropical posted will work, but I don't see where in your code you're attempting to check the value of prayerlevel.

    if you want it condensed, then use the ternary operator like you did w/ one of the ranged variables.

    prayerlevel = ((prayerlevel > 0) ? prayerlevel : 0);
Sign In or Register to comment.