Help w/ Friendship Algorithm please.

Pages: 1234
o ! i didnt think i could make it negative ! thank you !! well thats all i have for you right now :p if i have any other questions is it ok to post on here again ? ill fix the code up to make it more 'professional' and ill post the final code soon. thank you kemort once again
closed account (48T7M4Gy)
i know all the && doesn't look good but i just wanted it to work. i will look at what you just posted so i can learn new ways


You can see there are a number of ways of running through the logic you want and a few && are neither here nor there. As it turns out the if else structure I complained about is not too bad at all. So there you go. I think the thing that fussed me was the whiles and not really understanding what the overall flow was supposed to be.

The net result is though, all the controls structures - loops, whiles, ifs etc are all pretty much interchangeable.

Good luck with it.
thank you sir have a good night
closed account (48T7M4Gy)
is it ok to post on here again

Too easy - post again, happy to help if/where I can
hey kemort ! here it is :) i know it probably looks the same but i altered a few things
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

void CurrentFriendScore(int&, int);
char returner();

int main()
{
    int num = 0, FriendScore = 0;
    char foodQ = '0', sportsQ = '0', moviesQ = '0', beverageQ = '0';
    
   
    cout << "~ Phil's Friendship Algorithm ! ~ " << endl;
    cout << "********************************** " << endl;
    cout << "This program will implement a friendship algorithm to determine if someone could be your friend !" << endl;
    cout << "********************************** " << endl;
    cout << "100 is the best score. -20 is the worst ! " << endl;
    cout << "********************************** " << endl;
    cout << "Calling potential friend.." << endl;
    cout << "User answers phone " << endl; // USER INPUT STARTS

    
    
    // FOOD
    cout << "Hey ! Do you want to get some food? (y/n): " << endl;
    foodQ = returner();
    
    if (foodQ == 'Y')
    {
        cout << "Yay! What do you prefer ?" << "(1-Seafood, 2-steak, or 3-vegetarian) " << endl;
        cin >> num;
        CurrentFriendScore(FriendScore, num);
        
        cout << "Cool let's grub out . Can you pick me up ? " << endl;
        cout << "(1-Yes, 2-I lost my license, but my neighbor will take us, 3-Wow, you called me so you should pick ME up, but sure I'll come by soon) " << endl;
        cin >> num;
        CurrentFriendScore(FriendScore, num);
    }
   
    if (foodQ != 'Y')
    {
        // SPORTS
        cout << "Ok no problem. Do you like sports? (y/n): " << endl;
        sportsQ = returner();
    }
    
    if (sportsQ == 'Y')
    {
        cout << "Heck Ya ! Me too ! What do you want to play ?" << endl;
        cout << "(1-Basketball, 2-Baseball, 3-Football) " << endl;
        cin >> num;
         CurrentFriendScore(FriendScore, num);
        cout << "Awesome ! I lost my ball though .. can you bring one ? " << endl;
        cout << "(1-Yes, 2-I would but I don't have one either. I'll ask my neighbor, 3-No, you bring one) ";
        cin >> num;
         CurrentFriendScore(FriendScore, num);
    }
    
    if (foodQ != 'Y' && sportsQ != 'Y')
    {
        // MOVIES
        cout << "Alright. I'm tired anyways. How about a movie ?! (y/n) " << endl;
        moviesQ = returner();
    }
    
    if (moviesQ == 'Y')
    {
        cout << "Awesome ! What type of movie do you want to see ?" << endl;
        cout << "(1-Action, 2-Suspense, 3-Romance) " << endl;
        cin >> num;
         CurrentFriendScore(FriendScore, num);
        
        cout << "Cool ! I'll bring the popcorn ! Can you bring the drinks ? " << endl;
        cout << "(1-Yes, 2-Maybe, 3-No) " << endl;
        cin >> num;
         CurrentFriendScore(FriendScore, num);
    }
    
    if (foodQ != 'Y' && sportsQ != 'Y' && moviesQ != 'Y')
    {
        // BEVERAGES
        cout << "Ya movie tickets are pretty expensive. How about we get something to drink ? Nothing expensive or tiring. What do you say ? (y/n) " << endl;
        beverageQ = returner();
    }
    
    if (beverageQ == 'Y')
    {
        cout << " Cool lets do it. What kind of beverage do you want to get ? " << endl;
        cout << "(1-Coffee, 2-Beer, 3-Tea) " << endl;
        cin >> num;
         CurrentFriendScore(FriendScore, num);
        
        cout << "Cool, I'll come by and pick you up. See ya in a bit ! " << endl;
        cout << " O Wait !! Before I go, I wanted to tell you not to bring any money. I'll pay. Is that ok ?" << endl;
        cout << "(1-Yes, 2-Maybe, 3-No, I'm grown I can pay for myself) " << endl;
        cin >> num;
        CurrentFriendScore(FriendScore, num);
    }
    
    if (foodQ != 'Y' && sportsQ != 'Y' && moviesQ != 'Y' && beverageQ != 'Y')
    {
        cout << "Darn. Alright well I guess I'll talk to you later. Can I call back another time?" << endl;
        cout << "(1-Yes, 2-I'll call you, 3-No) " << endl;
        cin >> num;
         CurrentFriendScore(FriendScore, num);
    }
    
    
    return 0;
}

char returner()
{
    char reply = '0';
    cin >> reply;
    return toupper(reply);
}

void CurrentFriendScore(int &currentTotal, int x)
{
    int score = 0;
    
    if (x == 1)
        score = 50;
    if (x == 2)
        score = 25;
    if (x == 3)
        score = -10;
    
    currentTotal += score;
    cout << "*** Your friendscore is " << currentTotal << " !! ***" << endl;
    
    return;
}
closed account (48T7M4Gy)
Hi phil,

It worked - well done.

And I see you have some more snappy questions. Pity you didn't include the snappy answers to get the responses wrong but that's OK, your prof/teacher/tutor might not appreciate humor.

Are you sure -20 is the worst possible score? There are more than 2*'N' answers. But there again I replied with 'n' to every question and got 0.
o ya thats true. dang.. i already turned it in. wednesday by 5 pm is the deadline for 5% extra credit. its due tomorrow by 5. if i edit it and turn it in again i lose that 5% . but your right. i shouldve included snappy answers tho huh lol
o wait no -20 is the worst score you can get because the most questions you can answer for points is 2 questions. If you hit no then yes you can only answer 2questions unless its the last if statement which in that case -10 is the worst. do you know what i mean ? or maybe i am misunderstanding you
Last edited on
closed account (48T7M4Gy)
Don't worry Phil, I went back and checked and re-answered everything as no. I thinks its OK.
Take a well earned break.
Topic archived. No new replies allowed.
Pages: 1234