strange numbers?

This is a discussion on strange numbers? within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream> #include<cstdlib> int qualityPoints(int); // prototype int main() { int average; // declare variable cout<< "Enter your average"; // ...

  1. #1
    Registered User tu_user's Avatar
    Join Date
    Jan 2004
    Posts
    36

    Exclamation strange numbers?

    Code:
    #include<iostream>
    #include<cstdlib>
    int qualityPoints(int);	// prototype
    int main()
    {
    	int average;	// declare variable
    	cout<< "Enter your average";	// prompt the user for input
    	cin>> average;	// get input
    	cout<< qualityPoints(average);
     system("PAUSE");
     return 0;
    }
    int qualityPoints(int value)	// definition
    {
     if(value>89 && value<101)
                 return 4;
                 else if(value>79 && value<90)
                             return 3;
                             else if(value>69 && value<80)
                                  return 2;
                                  else if(value>59 && value<70)
                                       return 1;
                                       else if(value<60 && value>0)
                                            return 0; else cout<< "Enter within limit";
    }
    when I type 101 or higher it gives me 'Enter within limit' + some numbers. What are these numbers? I think there is some problem in loops. I don't know exactly.

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    127
    Code:
    int qualityPoints(int value)	// definition
    {
     if(value>89 && value<101)
             return 4;
             else if(value>79 && value<90)
                        return 3;
                        else if(value>69 && value<80)
                              return 2;
                              else if(value>59 && value<70)
                                   return 1;
                                   else if(value<60 && value>0)
                                       return 0; 
                                       else{ 
                                       cout<< "Enter within limit"; 
                                       return -1; //here,if you input a higher number, the function returns -1
                                       }
    }
    Regards
    Nana C++ Library is a GUI framework that designed to be C++ style, cross-platform and easy-to-use.

  3. #3
    Registered User tu_user's Avatar
    Join Date
    Jan 2004
    Posts
    36
    Thanku v m. So nice of u.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing unique numbers to an array
    By yardy in forum C Programming
    Replies: 6
    Last Post: 12-27-2006, 08:15 PM
  2. Strange results using dnsapi and windns
    By Niara in forum Networking/Device Communication
    Replies: 3
    Last Post: 08-13-2005, 10:21 AM
  3. Adding Line numbers in Word
    By Mister C in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 06-24-2004, 08:45 PM
  4. Prime Numbers
    By cmangel518 in forum C++ Programming
    Replies: 13
    Last Post: 04-30-2002, 11:51 PM
  5. Promlems with Random Numbers
    By Unregistered in forum C++ Programming
    Replies: 13
    Last Post: 03-20-2002, 07:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21