# The villiage idiot is back! -Function Help Please???

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 03-19-2004
Hammer
Quote:

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        &    |                    |     +--------------------+---------------------+---------------------+```
• 03-19-2004
Tronic
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?
• 03-19-2004
TWIXMIX
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
• 03-20-2004
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.

>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.
• 03-20-2004
TWIXMIX
Quote:

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
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12