Thread: C++, need help... Script not working when it should!

  1. #1
    Registered User
    Join Date
    May 2012
    Location
    Australia
    Posts
    5

    Question C++, need help... Script not working when it should!

    Hi alls....
    At the moment I'm a noob to C++ ("not the first time I've seen that" -You say)

    But i have been going through the tutorials and up up to um part 3 i think it is and i decided not to go any further until i make a test script so i did i tryd it worked good until!!!
    I can't seem to find the problem to my script?
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      float age, strength, intellegince, agility;
    
      cout<<"Please input your age: ";
      cin>> age;
      cin.ignore();
      if ( age < 30) {
         cout<<"You are pretty young!\n";
      }
      if (age < 60, age > 30 ) {
         cout<<"You are a adult\n";}
      if ( age < 101, age > 90 ) {
         cout<<"You are old\n";
      }
      if (age < 89, age > 61 ) {
         cout<<"You are getting old now arn't you\n";}
         cout<<"Press enter to continue\n";
    
      cin.get();
      cout<<"Please input your strength: ";
      cin>> strength;
      cin.ignore ();
      if ( strength < 30) {
      cout<<"You are weak\n";}
      if ( strength > 31, strength < 60) {
      cout<<"You have an average strength\n";}
      if ( strength > 61, strength < 89) {
      cout<<"You are quite strong\n";}
      if ( strength > 90, strength < 101){
         cout<<"You are very strong\n";}
         cout<<"Press enter to continue\n";
    
      cin.get();
      cout<<"Please input your intelligence:";
      cin>> intillegence;
      cin.ignore();
      if ( intelligence < 29) {
      cout<<"You are dumb\n";}
      if ( intelligence < 60, intelligence > 30) {
      cout<<"You have an average intelligence\n";}
      if ( intelligence < 89, intelligence > 61) {
      cout<<"You are quite smart\n";}
      if ( intelligence < 101, intelligence > 90){
         cout<<"You are very smart\n";}
         cout<<"Press enter to continue\n";
      cin.get();
    }
    When you run it its asks your age, strength, etc
    but when you enter 65 it displays the
    Code:
    if ( strength > 31, strength < 60) {
      cout<<"You have an average strength\n";}
      if ( strength > 61, strength < 89) {
      cout<<"You are quite strong\n";}
    Both "You have an average strength\n" and "You are quite strong\n"
    Why!? i had the problem when typing 45 but fixed it but now this?

    Someone please help!?

  2. #2
    Registered User antred's Avatar
    Join Date
    Apr 2012
    Location
    Germany
    Posts
    257
    Code:
    if ( strength > 31, strength < 60) {
    That's not how if-statements work. If you want to combine two or more boolean expressions, you can use either && (logical AND) or || (logical OR).

    Code:
    if ( strength > 31 && strength < 60) {

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Australia
    Posts
    5
    Quote Originally Posted by antred View Post
    Code:
    if ( strength > 31, strength < 60) {
    That's not how if-statements work. If you want to combine two or more boolean expressions, you can use either && (logical AND) or || (logical OR).

    Code:
    if ( strength > 31 && strength < 60) {
    ah ...
    right ...

    thank you very much
    sorry for not thinking lol
    Shall take a second look to the tutorial next time
    But thank you

  4. #4
    Broken Box of Syntax
    Join Date
    May 2012
    Location
    Florida
    Posts
    19
    Code:
    if ( strength > 31 && strength < 60) {
     cout<<"You have an average strength\n";}
     if ( strength > 61 && strength < 89) { 
        cout<<"You are quite strong\n";}
    Your going to run into an issue where numbers are 30, and 31 being entered.You need to make them >= or <=

    For example:
    Code:
     cin.get();
      cout<<"Please input your strength: ";
      cin>> strength;
      cin.ignore ();
      if ( strength <= 30) {
      cout<<"You are weak\n";}
      if ( strength >= 31 && strength < 60) {
      cout<<"You have an average strength\n";}
    By adding the line:

    Code:
     if ( strength <= 30) {
    You are saying If your strength is less then or equal to 30 then "you are weak."

    like wise the line:

    Code:
    if ( strength >= 31 && strength < 60) {
    Would say if your strength is greater then or equal to 31 AND your strength is less then 60 then "You have an average strength"

    The way it looks mathematically is:

    Weak = x
    X < 30

    like wise:

    average strength = y
    y > 31 and y < 60
    Last edited by Layvian; 05-19-2012 at 07:26 AM.

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    71
    Im a noob programmer also, and trust me soon the semantic bugs will dissapear and the debuging pain will begin

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    float age, strength, intellegince, agility;
    
    ...
    
    cout<<"Please input your intelligence:";
    cin>> intillegence;
    cin.ignore();
    if ( intelligence < 29) {
    ...
    Consistency is key. You have three different spellings of intelligence here, whatever one you choose (hopefully the right one) stick with it.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  7. #7
    Registered User
    Join Date
    May 2012
    Location
    Australia
    Posts
    5
    Sorry for late reply but thankyou everyone for your help and i have fixed all the things you guys pointed out (how embarrassing) but I' going to continue learning but Thanks Everyone
    Last edited by Max Winzar; 05-23-2012 at 06:44 PM.

  8. #8
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    @First Post: Things don't work good, they work well.
    @Fourth Post: You're*, not your.

    Not reading through the rest.

    Carry on.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. working with script kiddies
    By stevesmithx in forum General Discussions
    Replies: 17
    Last Post: 03-20-2011, 03:22 AM
  2. [PAID] Very simple C script - Not working?
    By spadez in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-12-2009, 08:00 AM
  3. Replies: 0
    Last Post: 02-05-2009, 06:59 PM
  4. Chemistry Problem In C++ Script Not WORKING
    By Thinker in forum C++ Programming
    Replies: 4
    Last Post: 03-09-2008, 09:02 AM
  5. No script errors. Why isnt my idea working?
    By Queatrix in forum C++ Programming
    Replies: 1
    Last Post: 09-15-2005, 06:31 PM