Help w/ Friendship Algorithm please.

Pages: 1234
Hi, so i'm supposed to write a program that determines the level of friendship with someone.
Each question i ask is supposed to utilize a function which i have at the bottom of my code but it may not be correct. Also for the questions dependent on the one before it, im suppose to have 1, 2, & 3 all have a specific point total to calculate the strength of our "friendship at the very end. I have it layed out how i want but i dont know if my function is correctly using the pass by reference that it should to change the values.
I was recommended to use a string to store a question that can be passed into the function as a parameter but im lost
Any guidance would be very appreciated :) Here is my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  #include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
    int a=1, b=2, c=3;
    double num1, num2, num3, num4, num5, FriendScore;
    char foodQ='Y', sportsQ='Y', moviesQ='Y', beverageQ='Y';
    
    

    cout << "Phil's Friendship Algorithm ! " << endl;
    
    cout << "Call potential friend" << endl;
    cout << "Brrrrring....." << endl;
    cout << "Brrrrring....." << endl;
    cout << "Brrr...... Hello ?" << endl;
    cout<< "Hey ! Do you want to get some food?: " << endl;
    
    if (foodQ == 'Y')
    {
        cout << "Yay! What do you prefer ?" <<  "(a-Seafood, b-steak, or c-vegetarian)";
        cin >> num1;
        
        cout << "Cool let's grub out . I'll pick you up.";
        cout << " Awesome see you in a bit.. friend ;) ! " << endl;
    }
    else if (foodQ == 'y')
    {
        while (foodQ == 'y')
        {
            cout << "Ok no problem. Do you like sports?: ";
            if (sportsQ == 'Y')
            {
                cout << "Heck Ya ! Me too ! What do you want to play ?" << "(a-Basketball, b-Baseball, c-Football) ";
                cin >> num2;
            }
            else if (sportsQ == 'y')
            {
                while (sportsQ == 'y')
                {
                    cout << "Alright. I'm tired anyways. How about a movie ?! ";
                }
                if (moviesQ == 'Y')
                {
                    cout << "Awesome ! What type of movie do you want to see ?" << "(a-Action, b-Suspense, c-Romance) ";
                    cin >> num3;
                    cout << "Cool ! See you in a bit ! I'll bring the popcorn ! " << endl;
                }
                else if (moviesQ == 'y')
                {
                    while (moviesQ == 'y')
                    {    cout << "Ya movie tickets are pretty expensive. How about we get something to drink ? Nothing expensive or tiring. What do you say ? ";
                    }
                    if (beverageQ == 'Y')
                    {
                        cout << " Cool lets do it. What kind of beverage do you want to get ? (a-Coffee, b-Beer, c-Tea) ";
                        cin >> num4;
                        cout << "Cool, I'll come by and pick you up. See ya in a bit ! ";
                        cout << " O Wait !! Before I go, I wanted to tell you not to bring any money. I'll pay since we're new friends. Is that ok ?" << "(a-Yes, b-Maybe, c-No) ";
                        cin >> num5;
                    }
                    else if (beverageQ == 'y')
                    {
                        cout << "Darn. Alright well I guess I'll talk to you later. " << endl;
                    }
                    
                    
                }
            }
        }
    }
    
    FriendScore = num1 + num2 + num3 + num4 + num5;
    cout << "You scored a" << FriendScore << "out of 50 ! This score represents how good of friends you will be !" << endl;
    
    return 0;
}

void Food(int &x, int &y, int &z)
void Sports(int &x, int &y, int &z)
void Movies(int &x, int &y, int &z)
void Beverage(int &x, int &y, int &z)
void Money(int &x,int &y, int &z)
{
    x = 10;
    y = 5;
    z = 1;
}
Last edited on
can someone please point me in the right direction ? :/
closed account (48T7M4Gy)
For a start you need ; at the end of lines.
hey kemort how are you buddy. i did do that but the example i recieved in class had them without ; . but ya xcode said to add them so i was confused. would you be willing to guide me with this program like the others ? this one isnt as long and isnt as complicated and i pretty much have it layed out exactly as i want it. i just need this function to add the x,y and z point values into a,b and c. i should have 1,2 & 3 instead but i dont know how to do that from a 'cin' . i learn more from you than i do in my class. ive been researching but nothing is similair to this :/
Last edited on
the program should end and calculate the friendScore if the user enters Y so if that is the first question then it should only calculate up to the point where a capital y for 'Yes' is entered. Will i need a string for this instead of the doubles ?
closed account (48T7M4Gy)
Once again this appears to be an example where you have cut code at the outset instead of having a plan of attack. That's why you are just being driven by taking advice for bits and pieces almost at random and seeing what happens next with an amazing array of decision ifs and elses.

Do you have a plan or just an idea?

As far as passing by reference why don't you test it? Insert cout's at strategic places to print out variables and see whether the function is getting it right. It's effectively a trace on what's going on.
-my plan of attack is to have these questions, some dependent on others that have an answering system that the user enters. the 3 choices (a,b,c) have specific point totals that i have in my function at the end. My program should add every choice picked associated with the specific score and add them up. The program should immediately calculate once the user enters a 'Y' for yes. any other letter entered is considered 'no' thus continuing on down the questions. :) That is my plan of attack.
- i just have trouble with the simplest things though. like having just one variable associated with a,b & c. ugh... lol ill test my function. ive tested it a lot today but it wont come out correctly. i just know it should look like/similair to that
Last edited on
closed account (48T7M4Gy)
So those are the only questions?
i mainly want it to be i.e. (1-Seafood, 2-steak, or 3-vegetarian) instead of (a-Seafood, b-steak, or c-vegetarian) because then i can just add the point values for a,b,c in my main and that defeats the purpose of my function..but i cant have an :
- int 1, 2, 3; or unsigned int 1, 2 3;
that wont work.
Last edited on
closed account (48T7M4Gy)
hey kemort how are you buddy.

I'm going well thanks.

i did do that but the example i recieved in class had them without

What can I say except my compiler would be very unhappy with your class. In fact so unhappy your class would come to a standstill and would not move forward until it was fixed.
closed account (48T7M4Gy)
Is the answer is always 1, 2 or 3 for each question?
closed account (48T7M4Gy)
Is the score always 10, 5 and 1 respectively?

These are simple questions I have asked 3 so far.
im surprise my teacher made that mistake ... wow..
so the user will enter 1 for "--" 2 for "--" or 3 for "--" for 5 questions that i have it for. yes 1, 2 or 3 is the answer for all the questions that ask for it
- 1 2 & 3 have their own point values.
- 1 is 10 points
- 2 is 5 points
- 3 is 1 point
Last edited on
What can I say except my compiler would be very unhappy with your class. In fact so unhappy your class would come to a standstill and would not move forward until it was fixed.


lol.
closed account (48T7M4Gy)
Phew, it's like extracting teeth, but what's new eh Phil. :)

Now, it's very simple, you can use a function to pass the answer (integer or character, whatever) to a function and get the function to update the running total and return it. You can even use your pass by reference skills. The function would just update the totalAffinity integer you declare in main.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void updateTotal( &totalAffinity, questionResult)
{
   /* 
   int score = ...;
   if ( questionResult == blah blah
        score = blah more blah
   
   if blah bla
   else
      3rd case

    totalAffinity += score;

   or you could (ideally) use a switch
*/
}

Last edited on
pulling teeth :p .. when i complete this program i have a questions off topic of this assignment but about c++ but we'll wait for that...
so is that ^ code at the end of my program after i return 0 ?
- is that if (questionResult) part all my if , else if, while statements?
- for .. int score = .. i still dont understand how it will calculate all the 1's, 2's & 3's the user enters. i was told to use a string to store a question that can be passed into the function as a parameter but im not sure if my string is supposed to be the 1's, 2's & 3's because thats what it sounds like
- i am not allowed to use switch statements unfortunately. i can use arrays now but i dont think it would be beneficial here
Last edited on
closed account (48T7M4Gy)
the updateTotal function replaces all that stuff you had at the end but outside main, ie lines 84 onwards.

And you need to put void updateTotal( int &, int ) at line 8. Read up on functions and their prototypes if you aren't clear.

Is that all the if statements - yes but only with regard to selecting how many points their answer receives.

Use if's if switches are out. I can handle that.


Use chars instead of strings. You don't need the answer to be a string. The user doesn't have to write a whole story if I understand it correctly.

1
2
if( questionResult== 'c' )
   score = 1;



OR

1
2
if( questionResult== 3 )
   score = 1;


All much the same.
Last edited on
ok ya not a james clavell novel story.. just a 1, 2 or 3 answer :p and ok so i will add the void . before the main() and then i will have the 3 if statements like you have above for the point totals. then i will have my if else if while statements. then ill return 0 then ill have the void... and the calculation on adding the score up.
:)
- how do i get my program to end and add the score up once the user enters a Y for yes. the program only continues until a Y is entered. Will i need another else if for each if statement that says ..
else if ( blah blah == 'Y') {
cout << totalAffinity << endl;

- i just want my program to add up until a "y or any letter' for 'no' is entered.
thanks
closed account (48T7M4Gy)
totalAffinity is a progressive total so you can stop anywhere you like and you'll get the right answer at the start, during and end.
Last edited on
ok thank you sir kemort . i will play around with it tonight and tomorrow and see if i can finish it. Ill be back tomorrow to let you know. hopefully i can get it to work ! :) have a good night
Last edited on
Pages: 1234