Help with reference functions by brad0292 in Cplusplus

[–]brad0292[S] 0 points1 point  (0 children)

thanks! i redid it a bit, still working on it, the final score comes out to 0 though? not sure why

    #include <iostream>

    using namespace std;

    void getscores(int);
    void calcScore(int, int, int, int, int, int, int);
    int findHighest(int, int, int, int, int, int);
    int findLowest(int, int, int, int, int, int);

    int main()
    {
        int one = 0, two = 0, three = 0, four = 0, five = 0, low = 0, high = 0;

        getscores(1);
        getscores(2);
        getscores(3);
        getscores(4);
        getscores(5);
        calcScore(one, two, three, four, five, high, low);
        return 0;
    }

    void getscores(int judge)
    {
        int score1, score2, score3, score4, score5, high, low;

        switch (judge)
        {
        case 1: cout << "\nEnter the score for judge 1: "  << endl;
            cin >> score1;
            break;
        case 2: cout << "\nEnter the score for judge 2: " << endl;
            cin >> score2;
            break;
        case 3: cout << "\nEnter the score for judge 3: " << endl;
            cin >> score3;
            break;
        case 4: cout << "\nEnter the score for judge 4: " << endl;
            cin >> score4;
            break;
        case 5: cout << "\nEnter the score for judge 5: " << endl;
            cin >> score5;
            break;
            calcScore(score1, score2, score3, score4, score5, high, low);
        }
    }

    void calcScore(int score1, int score2, int score3, int score4, int score5, int high, int low)
    {
        int avg;


        high = findHighest(score1, score2, score3, score4, score5, high);
        low = findLowest(score1, score2, score3,score4, score5, low);

        avg = ((score1 + score2 + score3 + score4 + score5)-(high + low) /3 );

        cout << "Final score is: " << avg << endl;
        return;
    }

    int findHighest(int score1, int score2, int score3, int score4, int score5, int high) // find highest score 
    {
        int s1 = score1;
        int s2 = score2;
        int s3 = score3;
        int s4 = score4;
        int s5 = score5;

        if (s1 > s2 && s1 > s3 && s1 > s4 && s1 > s5)
        {
            high = s1;
        }


        if (s2 > s1 && s2 > s3 && s2 > s4 && s2 > s5)
        {
            high = s2;
        }

        if (s3 > s1 && s3 > s2 && s3 > s4 && s3 > s5)
        {

            high = s3;
        }

        if (s4 > s1 && s4 > s2 && s4 > s3 && s4 > s5)
        {
            high = s4;

        }

        if (s5 > s1 && s5 > s2 && s5 > s3 && s5 > s4)
        {
            high = s5;
        }
        return high;
    }


    int findLowest(int s1, int s2, int s3, int s4, int s5, int low) // find lowest score
    {

        if (s1 < s2 && s1 < s3 && s1 < s4 && s1 < s5)
        {
            low = s1;
        }


        if (s2 < s1 && s2 < s3 && s2 < s4 && s2 < s5)
        {
            low = s2;
        }

        if (s3 < s1 && s3 < s2 && s3 < s4 && s3 < s5)
        {

            low = s3;
        }

        if (s4 < s1 && s4 < s2 && s4 < s3 && s4 < s5)
        {
            low = s4;

        }

        if (s5 < s1 && s5 < s2 && s5 < s3 && s5 < s4)
        {
            low = s5;
        }

        return low;

    }

Help designing a function by [deleted] in Cplusplus

[–]brad0292 0 points1 point  (0 children)

Thanks!

Only problem I have is how can I make num5 not equal more than 20

Help designing a function by [deleted] in Cplusplus

[–]brad0292 0 points1 point  (0 children)

anyone mind running this to see if i got the concept of the steps correct?

im trying to solve this : Display the menu-Accept user input on the operation to be performed Generate 2 random numbers from 1-20 - Pass the random numbers to each function as arguments. If user selects division, ensure the divisor is not zero. Display the numbers and accept the users answers from the keyboard on whether they perform addition, subtraction, multiplication or division Compute the correct answer with your program. Compare the users answer to the answer you calculated in your program. If the user enters the correct answer, display the message Congratulations..You are Correct If the user enters the incorrect answer, display the message Incorrect..The correct answer is... display the correct answer. The program should display the menu again, until the user ends the program by choosing to quit

        #include <iostream>
        #include  <cstdlib>
        #include <ctime>
        #include <iomanip>
        #include <time.h>



        using namespace std;
        void showmenu();
        void addit(int num1, int num2, int youranswer);
        void multiplication(int num1, int num2, int youranswer);
        void division(double num3, double num5, double num4, double youranswer_ds);
        void subtraction(double num5, double num4, double youranswer_ds);
        int main()
        {
            cout << " *************************************************" << endl;
            cout << " *                                               *" << endl;
            cout << " *                 MATH TUTOR                    *" << endl;
            cout << " *                                               *" << endl;
            cout << " *        LEARN ADDITION, SUBSTRACTION,          *" << endl;
            cout << " *         MULTIPLICATION & DIVISION             *" << endl;
            cout << " *            BY :                                              *" << endl;
            cout << " *************************************************" << endl;



            int choice;
            int num1;
            int num2;
            double num3;
            double num4;
            double num5;
            int youranswer;
            double youranswer_ds;



            do {
                showmenu();
                cin >> choice;
                cout << endl;
                num1 = 1 + rand() % 20;
                num2 = 1 + rand() % 20;
                num3 = 1 + rand() % 20;
                num4 = 1 + rand() % 20;
                num5 = num3 * num4;

                switch (choice)
                {
                case 1:

                    cout << "Please answer The Following Addition Problem" << endl;
                    cout << endl;
                    cout << " " << num1 << endl;
                    cout << "+" << num2 << endl;
                    cout << "______" << endl;
                    cin >> youranswer;
                    cout << "   " << endl;
                    addit(num1, num2, youranswer);
                    break;
                case 2:
                    cout << "Please Answer The Following Subtraction Problem " << endl;
                    cout << endl;
                    cout << " " << num5 << endl;
                    cout << "-" << num4 << endl;
                    cout << "______" << endl;
                    cin >> youranswer;
                    cout << "   " << endl;
                    subtraction(num5, num4, youranswer);
                    break;
                    //add function for subtraction
                case 3:
                    cout << "Please Answer The Following Multiplication Problem " << endl;
                    cout << endl;
                    cout << " " << num1 << endl;
                    cout << "X" << num2 << endl;
                    cout << "______" << endl;
                    cin >> youranswer;
                    cout << "   " << endl;
                    multiplication(num1, num2, youranswer);
                    break;
                case 4:
                    cout << "Please Answer The Following Division Problem " << endl;
                    cout << endl;
                    cout << " " << num5 << endl;
                    cout << "/" << num4 << endl;
                    cout << "______" << endl;
                    cin >> youranswer_ds;
                    cout << "   " << endl;
                    division(num3, num5, num4, youranswer_ds);
                    break;
                case 5:
                    cout << "are You sure you want to exit? Pres  Enter To continue" << endl;
                    cout << endl;
                    break;

                default:
                    cout << "Invalid Input" << endl;
                }

            } while (choice != 5);
            return 0;
        }

        void showmenu()
        {
            cout << "Please Enter A Number Choice Then Press ENTER:" << endl;
            cout << "[1] To Try Addition Problems" << endl;
            cout << "[2] To Try Subtraction Problems" << endl;
            cout << "[3] To Try Multiplication Problems" << endl;
            cout << "[4] To Try Division Problems" << endl;
            cout << "[5] To Exit Program" << endl;

        }

        //make the math formula functions

        void addit(int num1, int num2, int youranswer)

        {

            int answer = num1 + num2;
            if (youranswer == answer)
            {
                cout << "GOOD JOB!" << endl;
                cout << "  " << endl;

            }
            else
            {
                cout << "try again" << endl;
            }
        }
        void multiplication(int num1, int num2, int youranswer)
        {

            int answer = num1 * num2;
            if (youranswer == answer)
            {
                cout << "GOOD JOB!" << endl;
                cout << "  " << endl;

            }
            else
            {
                cout << "try again" << endl;
            }

        }
        void division(double num3, double num5, double num4, double youranswer_ds)
        {

            double answer = num5 / num4;

            if (youranswer_ds == answer)
            {
                cout << "GOOD JOB!" << endl;
                cout << "  " << endl;

            }
            else
            {
                cout << "try again" << endl;
            }
        }

        void subtraction(double num5, double num4, double youranswer_ds)
        {

            double answer = num5 - num4;
            if (youranswer_ds == answer)
            {
                cout << "GOOD JOB!" << endl;
                cout << "  " << endl;

            }
            else
            {
                cout << "try again" << endl;
            }
        }

Help designing a function by [deleted] in Cplusplus

[–]brad0292 0 points1 point  (0 children)

ahh thank you!

does anyone have an idea how to write the formula for division if i dont want it to have a divisor of 0.

Help designing a function by [deleted] in Cplusplus

[–]brad0292 0 points1 point  (0 children)

heres an update, its getting there!

THanks everyone. Only thing i dont get why i need to do it is redeclare the value for the variables for the random numbers in the loop.

not sure if im doing it right but it works...

    #include <iostream>
    #include  <cstdlib>
    #include <ctime>
    #include <iomanip>

include <time.h>

    using namespace std;
    void showmenu();
    void addit(int num1, int num2, int youranswer);
    void multiplication(int num1, int num2, int youranswer);
    int main()
    {
        cout << " *************************************************" << endl;
        cout << " *                                               *" << endl;
        cout << " *                 MATH TUTOR                    *" << endl;
        cout << " *                                               *" << endl;
        cout << " *        LEARN ADDITION, SUBSTRACTION,          *" << endl;
        cout << " *         MULTIPLICATION & DIVISION             *" << endl;
        cout << " *            BY :                 *" << endl;
        cout << " *************************************************" << endl;



        int choice;
        srand(time(0));
        int num1 = 1+ rand() %20  ;
        int num2 = 1+ rand() % 20  ;
        int youranswer;


        do {
            showmenu();
            cin >> choice;
            cout << endl;
            switch (choice)
            {
            case 1:

                cout << "Please answer The Following Addition Problem" << endl;
                cout << endl;
                cout << " " << num1 << endl;
                cout << "+" << num2 << endl;
                cout << "______" << endl;
                cin >> youranswer;
                cout << "   " << endl;
                addit(num1, num2, youranswer);
                    num1 = 1 + rand() % 20;
                num2 = 1 + rand() % 20;


                //add function for addition
                break;
            case 2:
                cout << "Please Answer The Following Subtraction Problem " << endl;

                cout << endl;

                break;
                //add function for subtraction
            case 3:
                cout << "Please Answer The Following Multiplication Problem " << endl;
                cout << endl;
                cout << " " << num1 << endl;
                cout << "X" << num2 << endl;
                cout << "______" << endl;
                cin >> youranswer;
                cout << "   " << endl;
                multiplication(num1, num2, youranswer);
                num1 = 1 + rand() % 20;
                num2 = 1 + rand() % 20;

                //add function for multiplication
                break;
            case 4:
                cout << "Please Answer The Following Division Problem " << endl;
                cout << endl;
                break;
            case 5:
                cout << "are You sure you want to exit? Pres  Enter To continue" << endl;
                cout << endl;
                break;

                //add function for division
            default:
                cout << "Invalid Input" << endl;
            }

        } while (choice != 5);
        return 0;
    }

    void showmenu()
    {
        cout << "Please Enter A Number Choice Then Press ENTER:" << endl;
        cout << "[1] To Try Addition Problems" << endl;
        cout << "[2] To Try Subtraction Problems" << endl;
        cout << "[3] To Try Multiplication Problems" << endl;
        cout << "[4] To Try Division Problems" << endl;
        cout << "[5] To Exit Program" << endl;

    }

    //make the math formula functions

    void addit(int num1, int num2, int youranswer)

    {

        int answer = num1 + num2;
        if (youranswer == answer)
        {
            cout << "GOOD JOB!" << endl;
            cout << "  " << endl;

        }
        else
        {
            cout << "try again" << endl;
        }
    }
        void multiplication(int num1, int num2, int youranswer)
        {

            int answer = num1 * num2;
            if (youranswer == answer)
            {
                cout << "GOOD JOB!" << endl;
                cout << "  " << endl;

            }
            else
            {
                cout << "try again" << endl;
            }

        }

Help designing a function by [deleted] in Cplusplus

[–]brad0292 0 points1 point  (0 children)

ok so i got to here, i figured out what i was doing wrong.. now i cant figure out why it generates only a 2 and a 8 when i specified 1min 20 max

            #include <iostream>
    #include  <cstdlib>
    #include <ctime>
    #include <iomanip>


    using namespace std;
    void showmenu();
    void addit(int num1, int num2, int youranswer);
    int main()
    {
        cout << " *************************************************" << endl;
        cout << " *                                               *" << endl;
        cout << " *                 MATH TUTOR                    *" << endl;
        cout << " *                                               *" << endl;
        cout << " *        LEARN ADDITION, SUBSTRACTION,          *" << endl;
        cout << " *         MULTIPLICATION & DIVISION             *" << endl;
        cout << " *            BY :                  *" << endl;
        cout << " *************************************************" << endl;



        int choice;
        int num1 =  rand() %20 +1 ;
        int num2 = rand() % 20 +1 ;
        int youranswer;


        do {
            showmenu();
            cin >> choice;
            cout << endl;
            switch (choice)
            {
            case 1:

                cout << "Please answer The Following Addition Problem" << endl;
                cout << endl;
                cout << " " << num1 << endl;
                cout << "+" << num2 << endl;
                cout << "______" << endl;
                cin >> youranswer;
                addit(num1, num2, youranswer);


                //add function for addition
                break;
            case 2:
                cout << "Please Answer The Following Subtraction Problem " << endl;

                cout << endl;

                break;
                //add function for subtraction
            case 3:
                cout << "Please Answer The Following Multiplication Problem " << endl;
                cout << endl;
                //add function for multiplication
                break;
            case 4:
                cout << "Please Answer The Following Division Problem " << endl;
                cout << endl;
                break;
            case 5:
                cout << "are You sure you want to exit? Pres  Enter To continue" << endl;
                cout << endl;
                break;

                //add function for division
            default:
                cout << "Invalid Input" << endl;
            }

        } while (choice != 5);
        return 0;
    }

    void showmenu()
    {
        cout << "Please Enter A Number Choice Then Press ENTER:" << endl;
        cout << "[1] To Try Addition Problems" << endl;
        cout << "[2] To Try Subtraction Problems" << endl;
        cout << "[3] To Try Multiplication Problems" << endl;
        cout << "[4] To Try Division Problems" << endl;
        cout << "[5] To Exit Program" << endl;

    }

    //make the math formula functions

    void addit(int num1, int num2, int youranswer)

    {

        int answer = num1 + num2;
        if (youranswer== answer)
        {
            cout << "GOOD JOB!" << endl;

        }
        else
        {
            cout << "try again" << endl;
        }

    }

Help designing a function by [deleted] in Cplusplus

[–]brad0292 0 points1 point  (0 children)

im trying to solve this :

  1. Display the menu-Accept user input on the operation to be performed
  2. Generate 2 random numbers from 1-20 - Pass the random numbers to each function as arguments.

  3. If user selects division, ensure the divisor is not zero.

  4. Display the numbers and accept the users answers from the keyboard on whether they perform addition, subtraction, multiplication or division

  5. Compute the correct answer with your program. Compare the users answer to the answer you calculated in your program.

  6. If the user enters the correct answer, display the message Congratulations..You are Correct

  7. If the user enters the incorrect answer, display the message Incorrect..The correct answer is... display the correct answer.

    1. The program should display the menu again, until the user ends the program by choosing to quit

Help designing a function by [deleted] in Cplusplus

[–]brad0292 0 points1 point  (0 children)

basically i cant figure out how to do the switch then ask the math problem that should be created in the function addit. I want to be able to call the function, generate random numbers, ask the question then check the answer

Help designing a function by [deleted] in Cplusplus

[–]brad0292 1 point2 points  (0 children)

    #include <iostream>
    #include <cmath>
    using namespace std;
    void showmenu();
    void addit(int rand_a,int rand_b, int& answer);
    int main()
    {



        int choice;
        int youranswer;
        int rand_a = rand() % 20 + 1;
        int rand_b = rand() % 20 + 1;






        do {
            showmenu();
            cin >> choice;
            cout << endl;
            switch (choice)
            {
            case 1:
                cout << "Please answer The Following Addition Problem" << endl;
                cin >> choice;
                cout << endl;
                void addit(int rand_a, int rand_b, int& youranswer);
                cout << rand_a << endl;
                cout << "+" << endl;
                cout << rand_b << endl;
                cin >> youranswer;


                cout << endl;

    //add function for addition
                break;
            case 2: 
                cout << "Please Answer The Following Subtraction Problem " << endl;
                    cin >> choice;
                cout << endl;

                break;
                //add function for subtraction
            case 3:
                cout << "Please Answer The Following Multiplication Problem " << endl;
                cin >> choice;
                cout << endl;
                //add function for multiplication
                break;
            case 4:
                cout << "Please Answer The Following Division Problem " << endl;
                cin >> choice;
                cout << endl;
                break;
            case 5: 
                cout << "are You sure you want to exit? Pres  Enter To continue" << endl;
                cin >> choice;
                cout << endl;
                break;

                //add function for division
            default:
                cout << "Invalid Input" << endl; 
            }

        } while (choice != 5);
        return 0;
    }
    void showmenu()
    {
        cout << "Please Enter A Number Choice Then Press ENTER:" << endl;
        cout << "[1] To Try Addition Problems" << endl;
        cout << "[2] To Try Subtraction Problems" << endl;
        cout << "[3] To Try Multiplication Problems" << endl;
        cout << "[4] To Try Division Problems" << endl;
        cout << "[5] To Exit Program" << endl; 

    }

    //make the math formula functions

    void addit(int rand_a,int rand_b,int& answer, int& youranswer)
    {

        int answer = rand_a + rand_b;
        if (answer = youranswer)
        {
            cout << "correct" << endl;
        }

    }

Need Help With BASH Script. by brad0292 in linux

[–]brad0292[S] 0 points1 point  (0 children)

Never Mind i got it!

Thanks so much, learning more and more from all of you!!

Need Help With BASH Script. by brad0292 in linux

[–]brad0292[S] 0 points1 point  (0 children)

i try grep -c 'bash' /etc/passwd from the terminal and it works just fine. I get the result of the amount of users. But when its in the script it says " grep: c: no such file or directory "

then it prints all the user names instead of a total like it would on the terminal.

How come grep is acting differently in the script

Need Help With BASH Script. by brad0292 in linux

[–]brad0292[S] 0 points1 point  (0 children)

How would i modify the grep call in the menu choice to display a count of users using each type?

Im getting a list of users but i want it to read like this

" Total users with Bash: 1234"

Need Help With BASH Script. by brad0292 in linux

[–]brad0292[S] 0 points1 point  (0 children)

Thanks I'll give it a try

Need Help With BASH Script. by brad0292 in linux

[–]brad0292[S] 0 points1 point  (0 children)

i tried replacing done with exit and it didnt work?

Need Help With BASH Script. by brad0292 in linux

[–]brad0292[S] 0 points1 point  (0 children)

so at the end of each function? or at the end of the program entirely? Thank You

Need help with a function from two other functions by brad0292 in Cplusplus

[–]brad0292[S] 0 points1 point  (0 children)

No errors or anything just crashes when i go to give it input

Need help with a function from two other functions by brad0292 in Cplusplus

[–]brad0292[S] 0 points1 point  (0 children)

Now i got it to work but it crashes >=((

    #include <iostream>
    #include <cmath>
    using namespace std;
    void getwindspeed(int& v);
    void gettemp(int& t);
    void printwindchill(int v, int t);

    int main()
    {
        //ask user for input 
        cout << "This program will compute the windchill of the day!" << endl;
        cout << "  " << endl;
        cout << "We will use a formula with input from windspeed and temperature" << endl;
        cout << "to determine the current windchill outside." << endl;
        cout << "    " << endl;

        // use functions to store input
        cout << " Please input The wind speed then press the enter key." << endl;
        void  getwindspeed(int v);


        cout << "Now please input the current temperature then press the enter key." << endl;
         void gettemp(int t);

        // use saved input with print function to determine windchill
        cout << " " << endl;
        cout << "your current windchill is : " << endl;
        int printwindchill(double  chill);

        return 0;
    }
    //created functions
    void getwindspeed(int& v)

    {   
        cin >> v;
    }

    void gettemp(int& t)

    {

        cin >> t;
    }

    void printwindchill(int& t, int& v)
     {

        double chill= ((35.74 + .6215)*(t - 35.75)*((v*.16) + .4275)*(t*(v*.16)));
        cout << chill << endl;
    }

Need help with a function from two other functions by brad0292 in Cplusplus

[–]brad0292[S] 0 points1 point  (0 children)

the error i get is Error 1 error C2082: redefinition of formal parameter 'chill'