Help w/ Friendship Algorithm please.

Pages: 1234
closed account (48T7M4Gy)
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
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int updateFriendScore(int);

int main()
{
	int a = 1, b = 2, c = 3;
	int num = 0, FriendScore = 0;
	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 ?" << "(1-Seafood, 2-steak, or 3-vegetarian)";
		cin >> num;
		FriendScore += updateFriendScore(num);

		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 ?" << "(1-Basketball, 2-Baseball, 3-Football) ";
				cin >> num;
				FriendScore += updateFriendScore(num);
			}
			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 ?" << "(1-Action, 2-Suspense, 3-Romance) ";
					cin >> num;
					FriendScore += updateFriendScore(num);
					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 ? (1-Coffee, 2-Beer, 3-Tea) ";
						cin >> num;
						FriendScore += updateFriendScore(num);
						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 >> num;
						FriendScore += updateFriendScore(num);
					}
					else if (beverageQ == 'y')
					{
						cout << "Darn. Alright well I guess I'll talk to you later. " << endl;
					}


				}
			}
		}
	}

	cout << "You scored a " << FriendScore << " out of 50 ! This score represents how good of friends you will be !" << endl;

	return 0;
}

int updateFriendScore( int x )
{
	int score = 0;
	
	if (x == 1)
		score = 10;

	if (x == 2)
		score = 5;
	if (x == 3)
		score = 1;
	else
		score = 0;

	return score;
}


As you indicate above, I noticed you never seem to ask ( what's the question being asked to give this answer anyway?) or get input on the Y/y answers. Presumably you are going to put those cin statement in. What about if the user types n?
do you mean if the user enters n instead of lower case y ? in a previous homework i had where i wanted my program to ask the user at the end if they wanted to start over from the beginning, i used a while loop . it looked like this without all the code in between. but it worked when the user entered anything except capital y for yes. is something different in my code now ?

1
2
3
4
5
6
7
8
9
10
11
 char again = 'Y';
  while (again == 'y' || again == 'Y')  // While loop to allow user to perform limitless computations or quit.
    { //all my code

 cout << "Would you like to perform another computation? (y/n) " ;
    cin >> again;
    }

    cout << "Have a great day ! Goodbye." << endl; // End of while loop
    }
    return 0;
oooo so you mean like this.. i see what you mean

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
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int updateFriendScore(int);

int main()
{
    int a = 1, b = 2, c = 3;
    int num = 0, FriendScore = 0;
    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;
    
    cin >> foodQ;
    
    if (foodQ == 'Y')
    {
        cout << "Yay! What do you prefer ?" << "(1-Seafood, 2-steak, or 3-vegetarian)";
        cin >> num;
        FriendScore += updateFriendScore(num);
        
        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?: ";
            cin >> sportsQ;
            if (sportsQ == 'Y')
            {
                cout << "Heck Ya ! Me too ! What do you want to play ?" << "(1-Basketball, 2-Baseball, 3-Football) ";
                cin >> num;
                FriendScore += updateFriendScore(num);
            }
            else if (sportsQ == 'y')
            {
                while (sportsQ == 'y')
                {
                    cout << "Alright. I'm tired anyways. How about a movie ?! ";
                    cin >> moviesQ;
                }
                if (moviesQ == 'Y')
                {
                    cout << "Awesome ! What type of movie do you want to see ?" << "(1-Action, 2-Suspense, 3-Romance) ";
                    cin >> num;
                    FriendScore += updateFriendScore(num);
                    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 ? ";
                        cin >> beverageQ;
                    }
                    if (beverageQ == 'Y')
                    {
                        cout << " Cool lets do it. What kind of beverage do you want to get ? (1-Coffee, 2-Beer, 3-Tea) ";
                        cin >> num;
                        FriendScore += updateFriendScore(num);
                        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 >> num;
                        FriendScore += updateFriendScore(num);
                    }
                    else if (beverageQ == 'y')
                    {
                        cout << "Darn. Alright well I guess I'll talk to you later. " << endl;
                    }
                    
                    
                }
            }
        }
    }
    
    cout << "You scored a " << FriendScore << " out of 50 ! This score represents how good of friends you will be !" << endl;
    
    return 0;
}

int updateFriendScore( int x )
{
    int score = 0;
    
    if (x == 1)
        score = 10;
    
    if (x == 2)
        score = 5;
    if (x == 3)
        score = 1;
    else
        score = 0;
    
    return score;
}
if i want to add more questions... because if the user enters Y for the first question, thats a quick program.. just 1 score, 1 answer, program over.. if i want to ask more questions not dependent on the question before it, where do i write those questions ? is it another else if ? but i would do that else if at the end of these answers where a no was answered. as an example ...

1
2
3
4
5
6
7
8
9
10


else if (foodQ == 'Y')
{ cout << "Do you want to play video games?" ;
}
    {
        while (foodQ == 'Y')
        {
            cout << "Cool ! What gaming console do you have? (1-Playstation, 2-XBox, 3-Nintendo64: ";
            cin >> videoGamesQ;
Last edited on
nvm .. ignore all that .... if the user answers yes, then thats what there going to do.. theres no point asking to do other stuff. sorry my brain farted
Last edited on
i ran the code but it doesnt recognize y & Y as yes and everything else as no for some reason.. ughh.. ill go over it tonight and tomorrow. see ya kemort ! thanks buddy
closed account (48T7M4Gy)
Take a break Phil. :)
i fixed the y thing.. but it doesnt add up the score and when i get to the movie part it just repeats. but at least its almost there :) i will rewrite this program i just wanted to test it how you did it . ok your right . break time . see ya later ! lol
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
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int updateFriendScore(int);

int main()
{
    int a = 1, b = 2, c = 3;
    int num = 0, FriendScore = 0;
    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;
    
    cin >> foodQ;
    
    if (foodQ == 'y')
    {
        cout << "Yay! What do you prefer ?" << "(1-Seafood, 2-steak, or 3-vegetarian)";
        cin >> num;
        FriendScore += updateFriendScore(num);
        
        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?: ";
            cin >> sportsQ;
            if (sportsQ == 'y')
            {
                cout << "Heck Ya ! Me too ! What do you want to play ?" << "(1-Basketball, 2-Baseball, 3-Football) ";
                cin >> num;
                FriendScore += updateFriendScore(num);
            }
            else if (sportsQ != 'y')
            {
                while (sportsQ != 'y')
                {
                    cout << "Alright. I'm tired anyways. How about a movie ?! ";
                    cin >> moviesQ;
                }
                if (moviesQ == 'y')
                {
                    cout << "Awesome ! What type of movie do you want to see ?" << "(1-Action, 2-Suspense, 3-Romance) ";
                    cin >> num;
                    FriendScore += updateFriendScore(num);
                    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 ? ";
                        cin >> beverageQ;
                    }
                    if (beverageQ == 'y')
                    {
                        cout << " Cool lets do it. What kind of beverage do you want to get ? (1-Coffee, 2-Beer, 3-Tea) ";
                        cin >> num;
                        FriendScore += updateFriendScore(num);
                        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 >> num;
                        FriendScore += updateFriendScore(num);
                    }
                    else if (beverageQ != 'y')
                    {
                        cout << "Darn. Alright well I guess I'll talk to you later. " << endl;
                    }
                    
                    
                }
            }
        }
    }
    
    cout << "You scored a " << FriendScore << " out of 50 ! This score represents how good of friends you will be !" << endl;
    
    return 0;
}
Last edited on
closed account (48T7M4Gy)
You've missed putting in the function at the bottom. (my lines 93 to 108 or thereabouts.)
Last edited on
this is the code. i just didnt copy/paste it all here but i ran it right. a,b & c are unused variables maybe that has something to dowith it. im goin to bed tho ill try and figure it out tomoro. good night !

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
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int updateFriendScore(int);

int main()
{
    int a = 1, b = 2, c = 3;
    int num = 0, FriendScore = 0;
    char foodQ = 'y', sportsQ = 'y', moviesQ = 'y', beverageQ = 'y';
    
    cout << "~ Phil's Friendship Algorithm ! ~ " << endl;
    
    cout << "Calling potential friend.." << endl;
    cout << "Brrrrring....." << endl;
    cout << "Brrrrring....." << endl;
    cout << "Brrr...... Hello ?" << endl;
    cout << "Hey ! Do you want to get some food? (y/n): " << endl;
    
    cin >> foodQ;
    
    if (foodQ == 'y')
    {
        cout << "Yay! What do you prefer ?" << "(1-Seafood, 2-steak, or 3-vegetarian)";
        cin >> num;
        FriendScore += updateFriendScore(num);
        
        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? (y/n): ";
            cin >> sportsQ;
            if (sportsQ == 'y')
            {
                cout << "Heck Ya ! Me too ! What do you want to play ?" << "(1-Basketball, 2-Baseball, 3-Football) ";
                cin >> num;
                FriendScore += updateFriendScore(num);
            }
        
            else if (sportsQ != 'y')
            {
                while (sportsQ != 'y')
                {
                    cout << "Alright. I'm tired anyways. How about a movie ?! (y/n) ";
                    cin >> moviesQ;
                }
                if (moviesQ == 'y')
                {
                    cout << "Awesome ! What type of movie do you want to see ?" << "(1-Action, 2-Suspense, 3-Romance) ";
                    cin >> num;
                    FriendScore += updateFriendScore(num);
                    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 ? (y/n) ";
                        cin >> beverageQ;
                    }
                    if (beverageQ == 'y')
                    {
                        cout << " Cool lets do it. What kind of beverage do you want to get ? (1-Coffee, 2-Beer, 3-Tea) ";
                        cin >> num;
                        FriendScore += updateFriendScore(num);
                        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 ?" << "(1-Yes, 2-Maybe, 3-No) ";
                        cin >> num;
                        FriendScore += updateFriendScore(num);
                    }
                    else if (beverageQ != 'y')
                    {
                        cout << "Darn. Alright well I guess I'll talk to you later. " << endl;
                    }
                    
                    
                }
            }
        }
    }
    
    cout << "You scored a " << FriendScore << " out of 50 ! This score represents how good of friends you will be !" << endl;
    
    return 0;
}

int updateFriendScore( int x )
{
    int score = 0;
    
    if (x == 1)
        score = 10;
    
    if (x == 2)
        score = 5;
    if (x == 3)
        score = 1;
    else
        score = 0;
    
    return score;
}
im still having issues getting it to work fluently & correctly to the end. i tried change a bunch of stuff but it still repeats line 60 regardless of what i type and it doesnt add the score at all . I have an inkling it might be my '}' and how they are set up throughout my if else if whiles etc but i couldnt get that to work also. idk whats wrong :( as usual.... gah..
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
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int updateFriendScore(int);

int main()
{
    int a = 1, b = 2, c = 3;
    int num = 0, FriendScore = 0;
    char foodQ = 'y', sportsQ = 'y', moviesQ = 'y', beverageQ = 'y';
    
    cout << "~ Phil's Friendship Algorithm ! ~ " << endl;
    
    cout << "Calling potential friend.." << endl;
    cout << "Brrrrring....." << endl;
    cout << "Brrrrring....." << endl;
    cout << "Brrr...... Hello ?" << endl;
    cout << "Hey ! Do you want to get some food? (y/n): " << endl;
    
    cin >> foodQ;
    
    if (foodQ == 'y' || foodQ == 'Y')
    {
        cout << "Yay! What do you prefer ?" << "(1-Seafood, 2-steak, or 3-vegetarian)";
        cin >> num;
        FriendScore += updateFriendScore(num);
        
        cout << "Cool let's grub out . I'll pick you up.";
        cout << " Awesome see you in a bit.. friend ;) ! " << endl;
    }
    else if (foodQ != 'y' && foodQ != 'Y')
    {
        while (foodQ != 'y' && foodQ != 'Y')
        {
            cout << "Ok no problem. Do you like sports? (y/n): ";
            cin >> sportsQ;
            if (sportsQ == 'y' || sportsQ == 'Y')
            {
                cout << "Heck Ya ! Me too ! What do you want to play ?" << "(1-Basketball, 2-Baseball, 3-Football) ";
                cin >> num;
                FriendScore += updateFriendScore(num);
            }
        
            else if (sportsQ != 'y' && sportsQ != 'Y')
            {
                while (sportsQ != 'y' && sportsQ != 'Y')
                {
                    cout << "Alright. I'm tired anyways. How about a movie ?! (y/n) ";
                    cin >> moviesQ;
                }
                if (moviesQ == 'y' || moviesQ == 'Y')
                {
                    cout << "Awesome ! What type of movie do you want to see ?" << "(1-Action, 2-Suspense, 3-Romance) ";
                    cin >> num;
                    FriendScore += updateFriendScore(num);
                    cout << "Cool ! See you in a bit ! I'll bring the popcorn ! " << endl;
                }
                else if (moviesQ != 'y' && moviesQ != 'Y')
                {
                    while (moviesQ != 'y' && moviesQ != 'Y')
                    {
                        cout << "Ya movie tickets are pretty expensive. How about we get something to drink ? Nothing expensive or tiring. What do you say ? (y/n) ";
                        cin >> beverageQ;
                    }
                    if (beverageQ == 'y' || beverageQ == 'Y')
                    {
                        cout << " Cool lets do it. What kind of beverage do you want to get ? (1-Coffee, 2-Beer, 3-Tea) ";
                        cin >> num;
                        FriendScore += updateFriendScore(num);
                        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 ?" << "(1-Yes, 2-Maybe, 3-No) ";
                        cin >> num;
                        FriendScore += updateFriendScore(num);
                    }
                    else if (beverageQ != 'y' && beverageQ != 'Y')
                    {
                        cout << "Darn. Alright well I guess I'll talk to you later. " << endl;
                    }
                    
                    
                }
            }
        }
    }
    
    cout << "You scored a " << FriendScore << " ! This score represents how good of friends you will be !" << endl;
    
    return 0;
}

int updateFriendScore( int x )
{
    int score = 0;
    
    if (x == 1)
        score = 10;
    
    if (x == 2)
        score = 5;
    if (x == 3)
        score = 1;
    else
        score = 0;
    
    return score;
}
Last edited on
this is what it looks like when i ran it. i changed the 'int x' at the end to 'num' just to try it out but it still does what 'x' did. would a for loop be the difference instead of a while ?
~ Phil's Friendship Algorithm ! ~ 
Calling potential friend..
Brrrrring.....
Brrrrring.....
Brrr...... Hello ?
Hey ! Do you want to get some food? (y/n): 
n
Ok no problem. Do you like sports? (y/n): y
Heck Ya ! Me too ! What do you want to play ?(1-Basketball, 2-Baseball, 3-Football) 1
Ok no problem. Do you like sports? (y/n): 1
Alright. I'm tired anyways. How about a movie ?! (y/n) 1
Alright. I'm tired anyways. How about a movie ?! (y/n) 1
Alright. I'm tired anyways. How about a movie ?! (y/n) 
Last edited on
closed account (48T7M4Gy)
Well Phil I'm back again and I just had a look at it.

I don't have an instant answer except to say your while loop has no 'escape clause'.

Because you have so many decisions being mad with whiles and if's I think you would be best off drawing a flowchart. Do you know how to draw a flowchart? It doesn't have to be complicated but you'll find it's a perfect way to handle this problem.

Also I suggest you use toupper() rather that the repeated 'y' 'Y' stuff. Simplify, don't complicate.

Lines 29 and 38 do exactly the same thing and yet they are supposed to be if (that) else (this) You have if(that) else (that) . A bit suspect.

hey kemort how are you . i do know how to draw a flowchart. ill do that right now to see if that sparks any lightbulbs . I looked at 29 and 28 but i dont see what you mean about them being the same. 29 says if foodQ = y AND* Y .. 28 says it food doesnt = y or doesnt = Y. Do i need to make it an else instead of an else if ? does that mean i will need to do that for all my else ifs ?
Last edited on
ok when i changed it to else it did this which it didnt do before but still didnt work. it just loops and loops back to the movie line then repeats repeats repeats im working on the flowchart
~ Phil's Friendship Algorithm ! ~ 
Calling potential friend..
Brrrrring.....
Brrrrring.....
Brrr...... Hello ?
Hey ! Do you want to get some food? (y/n): 
n
Ok no problem. Do you like sports? (y/n): y
Heck Ya ! Me too ! What do you want to play ?(1-Basketball, 2-Baseball, 3-Football) 3
Awesome ! What type of movie do you want to see ?(1-Action, 2-Suspense, 3-Romance) 3
Cool ! See you in a bit ! I'll bring the popcorn ! 
 Cool lets do it. What kind of beverage do you want to get ? (1-Coffee, 2-Beer, 3-Tea) 
Last edited on
closed account (48T7M4Gy)
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
#include <string>
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int updateFriendScore(int);
char responder();

int main()
{
	int a = 1, b = 2, c = 3;
	int num = 0, FriendScore = 0;
	char response = 'Y', foodQ = '0', sportsQ = '0', moviesQ = '0', beverageQ = '0';

	cout << "~ Phil's Friendship Algorithm ! ~ " << endl;
	cout << "Calling potential friend.." << endl;
	cout << "Brrrrring....." << endl;
	cout << "Brrrrring....." << endl;
	cout << "Brrr...... Hello ?" << endl;


	// TRY FOOD
	cout << "Hey ! Do you want to get some food? (y/n): " << endl;
	foodQ = responder();

	if (foodQ == 'Y')
	{
		cout << "Yay! What do you prefer ?" << "(1-Seafood, 2-steak, or 3-vegetarian)";
		cin >> num;
		FriendScore += updateFriendScore(num);

		cout << "Cool let's grub out . I'll pick you up.";
		cout << " Awesome see you in a bit.. friend ;) ! " << endl;
	}

	if (foodQ != 'N')
	{
		//TRY SPORTS
		cout << "Ok no problem. Do you like sports? (y/n): ";
		sportsQ = responder();
	}

	if (sportsQ == 'Y')
	{
		cout << "Heck Ya ! Me too ! What do you want to play ?" << "(1-Basketball, 2-Baseball, 3-Football) ";
		cin >> num;
		FriendScore += updateFriendScore(num);
	}

	if (sportsQ != 'N')
	{
		//TRY MOVIES
		cout << "Alright. I'm tired anyways. How about a movie ?! (y/n) ";
		moviesQ = responder();
	}

	if ( moviesQ == 'Y' )
	{
		cout << "Awesome ! What type of movie do you want to see ?" << "(1-Action, 2-Suspense, 3-Romance) ";
		cin >> num;
		FriendScore += updateFriendScore(num);
		cout << "Cool ! See you in a bit ! I'll bring the popcorn ! " << endl;
	}

	if (moviesQ != 'N')
	{
		//TRY 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) ";
		beverageQ = responder();
	}

	if (beverageQ == 'Y')
	{
		cout << " Cool lets do it. What kind of beverage do you want to get ? (1-Coffee, 2-Beer, 3-Tea) ";
		cin >> num;
		FriendScore += updateFriendScore(num);
		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 ?" << "(1-Yes, 2-Maybe, 3-No) ";
		cin >> num;
		FriendScore += updateFriendScore(num);
	}

	if (beverageQ != 'N')
		cout << "Darn. Alright well I guess I'll talk to you later. " << endl;

	cout << "You scored a " << FriendScore << " ! This score represents how good of friends you will be !" << endl;

	system("pause");

	return 0;
}

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

int updateFriendScore(int x)
{
	int score = 0;

	if (x == 1)
		score = 10;

	if (x == 2)
		score = 5;
	if (x == 3)
		score = 1;
	//else                            <- oops
		//score = 0;           <- oops

	return score;
}
Last edited on
thank you kemort. but my code outputted this for that ^ code. i need it to where once i enter a y or Y for yes then i will get to the choice of picking 1, 2 or 3. once i enter a number it should immediately go to where it tells me my score. if i enter anything other than y orY it should continue to the next question. im almost done with the flowchart
~ Phil's Friendship Algorithm ! ~ 
Calling potential friend..
Brrrrring.....
Brrrrring.....
Brrr...... Hello ?
Hey ! Do you want to get some food? (y/n): 
Y
Yay! What do you prefer ?(1-Seafood, 2-steak, or 3-vegetarian)2
Cool let's grub out . I'll pick you up. Awesome see you in a bit.. friend ;) ! 
Ok no problem. Do you like sports? (y/n): Y
Heck Ya ! Me too ! What do you want to play ?(1-Basketball, 2-Baseball, 3-Football) 3
Alright. I'm tired anyways. How about a movie ?! (y/n) N
 Cool lets do it. What kind of beverage do you want to get ? (1-Coffee, 2-Beer, 3-Tea) N
Cool, I'll come by and pick you up. See ya in a bit !  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 ?(1-Yes, 2-Maybe, 3-No) Darn. Alright well I guess I'll talk to you later. 
You scored a 1 ! This score represents how good of friends you will be !
Last edited on
closed account (48T7M4Gy)
I've changed it slightly.

it should immediately go to where it tells me my score.

Then all you do is incorporate the data display code in the updateFriendScore() function.

if i enter anything other than y or Y it should continue to the next question.

Then just change the logic inside the if statement(s).

The overall impression I get is there is just a cascade of questions. If one doesn't suit the answer then the program just goes to the next one that does.
yes you are correct; a cascade of questions that are asked until the user (person recieving the "phone call" answers yes and picks what he wants to do/eat/drink) then displays the score.
-what do you mean by incorporate the data display code in the function ? do you mean updateFriendScore(int Friendscore) ? because friendscore is what i want outputted. As it is the program doesnt recognize the formula. :)
-i finished the flow chart. its nice to see exactly what i want in a picture-esque form. but when it comes to translating it to code, i have trouble with that because i'm not an adept programmer. I've learned a lot but functions are new and challenging. but this is fun i like to learn and struggle a little bit. thank you
Last edited on
closed account (48T7M4Gy)
what do you mean by incorporate the data display code in the function ?

Just write some code by adding/incorporating/including it in the function to display/print/output the current score.

do you mean updateFriendScore(int Friendscore) ?

Yes/correct/agree/positive but it will have to be modified slightly with an additional parameter, I nearly forgot :]

because friendscore is what i want outputted.

I know/understand/comprehend/gather that and that's what I'm talking about also.

As it is the program doesnt recognize the formula.

What formula do you mean? Because my program does in fact recognise the scoring formula! :)
Last edited on
Pages: 1234