Thread: The villiage idiot is back! -Function Help Please???

  1. #16
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by JaWiB
    Wow, I've never heard that before. Learn something new every day I guess
    Here, learn some others too :
    Code:
        +--------------------+---------------------+---------------------+
        |alternate   primary | alternate   primary | alternate   primary |
        +--------------------+---------------------+---------------------+
        |   <%          {    |    and        &&    |  and_eq       &=    |
        +--------------------+---------------------+---------------------+
        |   %>          }    |   bitor        |    |   or_eq       |=    |
        +--------------------+---------------------+---------------------+
        |   <:          [    |    or         ||    |  xor_eq       ^=    |
        +--------------------+---------------------+---------------------+
        |   :>          ]    |    xor         ^    |    not         !    |
        +--------------------+---------------------+---------------------+
        |   %:          #    |   compl        ~    |  not_eq       !=    |
        +--------------------+---------------------+---------------------+
        |  %:%:        ##    |  bitand        &    |                     |
        +--------------------+---------------------+---------------------+
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  2. #17
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    oo, Interesting info hammer Good too know.

    Your...making this too hard on yourself I think......

    Are there specific requirements/reasons your doing the things your doing on this assignment?

    I don't know but...I just think your doing too much work..

    Heres the code I came up with, and this doesn't mean I want you to do this at all...it just means that theres easier ways to do things. You don't need to do that much, you know? Simple problems require the simplest solutions

    Code:
    #include <iostream>
    #include <stdlib.h>
    float Calc_Grades(float grade);
    float Calc_Grades(float grade)
    {
        if (grade >= 0.0f && grade <= 65.0f)
        {
            std::cout << "The grade of " << grade  << " is an F.";
        }
        else if (grade >= 65.01f && grade <= 71.0f)
        {
            std::cout << "The grade of " << grade << " is a D.";
        }
        else if (grade >= 72.0f && grade <= 85.0f)
        {
            std::cout << "The grade of" << grade << " is a C.";
        }
        else if (grade >= 85.01f && grade <= 93.0f)
        {
            std::cout << "The grade of " << grade << " is a B.";
        }
        else if (grade >= 93.01f && grade <= 200.0f)
        {    
            std::cout << "The grade of " << grade << " is an F";
        }
    }
    
    int main()
    {
        std::cout << "Input grade percentage please: ";
        float percent;
            std::cin >> percent;
        Calc_Grades(percent);
            std::cout << "\n";
        system("pause");
        return 0;
    }
    For one main() is too big, which is a problem alot of times, and you don't need to loop, don't even have to return a value in functions or use a header file.. Just make it simpler is all I think But you'll learn that later.

    You could even use args in main() so it would make it easier for the user.... so lets say you could pass into main() '95.5' or something and it would calculate and output, without you having to run the program and type it in..you could simply go into run and type in the prog name and enter in the value..but thats more then you have to worry about.

    Does this help a little bit?
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  3. #18
    Programmer in Training TWIXMIX's Avatar
    Join Date
    Feb 2004
    Posts
    57
    Code:
    #include <iostream>
    #include <stdlib.h>
    using namespace std; 
    
    float Calc_Grades(float grade); 
    float Calc_Grades(float grade)
    {
        if (grade >= 0.0f && grade <= 65.0f)
        {
            cout << "The grade of " << grade  << " is an F.";
        }
        else if (grade >= 65.01f && grade <= 71.0f)
        {
            cout << "The grade of " << grade << " is a D.";
        }
        else if (grade >= 72.0f && grade <= 85.0f)
        {
            cout << "The grade of" << grade << " is a C.";
        }
        else if (grade >= 85.01f && grade <= 93.0f)
        {
            cout << "The grade of " << grade << " is a B.";
        }
        else if (grade >= 93.01f && grade <= 200.0f)
        {    
            cout << "The grade of " << grade << " is an F";
        }
    }
    
    int main()
    {
        cout << "Input grade percentage please: ";
        float percent;
        cin >> percent;
        Calc_Grades(percent);
        cout << "\n";
        system("pause");
        return 0;
    }
    THe code in red is not needed. The reason for this is becasue its before main() so the compiler already knows it was there. You would need this though if you placed float Calc_grades() below int main.

    in blue i've added using namespace std;
    As you may have noticed I also got rid all the std::'s.
    namespace std; automatically adds those just to save alot of hassle.

    But other then that the code was right.
    And alot easier then ur old code

  4. #19
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    >THe code in red is not needed. The reason for this is becasue its before main() so the compiler already knows it was there.

    My compiler freaks out if I don't declare a function prototype before I define the function.

    >in blue i've added using namespace std;
    I can understand std::cout better then cout <<.
    The reason I did this was so that I could see exactly what was going on in my code, doing the latter just makes me ignorant to the inner workings of the program, thats the only reason why but yes it's not needed other then that. The output is the same.
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  5. #20
    Programmer in Training TWIXMIX's Avatar
    Join Date
    Feb 2004
    Posts
    57
    Originally posted by Tronic
    >THe code in red is not needed. The reason for this is becasue its before main() so the compiler already knows it was there.

    My compiler freaks out if I don't declare a function prototype before I define the function.
    O mine doesnt.
    As long as the function is before int main () I don't need the function prototype with devc++.

    other then that is outputs the same result ya

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Calling a Thread with a Function Pointer.
    By ScrollMaster in forum Windows Programming
    Replies: 6
    Last Post: 06-10-2006, 08:56 AM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. using push back function of a vector class template
    By anti-hw in forum C++ Programming
    Replies: 1
    Last Post: 07-20-2002, 11:25 AM