| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
ok i keep getting this error message and i cant understand why can someone please help quick, this is a final project and it is due in about 4 hours... yes sad i know here is the program and the error msg
#include "stdafx.h" #include <math.h> #include <iostream.h> #include <iomanip.h> #include <string.h> double results (double overall); int main(int argc, char* argv[]) { double overall; int outgoing; char answer; outgoing = 0; cout << "You are about to take a personality quiz," << endl; cout << "answer the questions based on what you" << endl; cout << "would do in each situation." << endl; cout << " " << endl; cout << " #1 " << endl << "You're at a party. Do you talk to people you don't know? (A (Yes), B (Only if they talk to you), C(No))"; cin >> answer; if(answer=='A' || answer=='a') { outgoing = outgoing +1; overall = overall +1; } if(answer=='B' || answer=='b') { outgoing = outgoing +0; overall = overall +0; } if(answer=='C' || answer=='c') { outgoing = outgoing -1; overall = overall -1; } char answer2; cout << " #2 " << endl << "Your significant other has invited you to a family gathering for the first time, do you...(A, B, C)" << endl; cout << "A) Make pleasant conversation." << endl; cout << "B) Only speak when spoken to." << endl; cout << "C) Say nothing to anyone." << endl; cin >> answer2; if(answer2=='A' || answer2=='a') { outgoing = outgoing +1; overall = overall +1; } if(answer2=='B' || answer2=='b') { outgoing = outgoing +0; overall = overall +0; } if(answer2=='C' || answer2=='c') { outgoing = outgoing -1; overall = overall -1; } { switch (outgoing) { case -2: case -1: cout << "You dont have a very outgoing personality, make some more friends and get out of the house more." << endl; break; case 0: cout << "You have a decent outgoing personality, but it can use some work, meet new people and try new things." << endl; break; case 1: case 2: cout << "You have a great outgoing personality, good job, you are a cool person." << endl; } cout << endl; cout << endl; } int courage; char answer3; courage = 0; cout << " #3 " << endl << "You are at a bar, a girl smiles at you what do you do? (A, B, C)" << endl; cout << "A) Walk over to her and start up a coversation." << endl; cout << "B) Walk in her direction and keep walking to see if she says something to you" << endl; cout << "C) Wait to see if she will come to you" << endl; cin >> answer3; if(answer3=='A' || answer3=='a') { courage = courage +1; overall = overall +1; } if(answer3=='B' || answer3=='b') { courage = courage +0; overall = overall +0; } if(answer3=='C' || answer3=='c') { courage = courage -1; overall = overall -1; } char answer4; cout << " #4 " << endl << "You are at a school dance. You... (A, B, C)" << endl; cout << "A) Go find your crush and dance with them." << endl; cout << "B) Mingle with your friends for the night." << endl; cout << "C) Just walk around listening to the music." << endl; cin >> answer4; if(answer4=='A' || answer4=='a') { courage = courage +1; overall = overall +1; } if(answer4=='B' || answer4=='b') { courage = courage +0; overall = overall +0; } if(answer4=='C' || answer4=='c') { courage = courage -1; overall = overall -1; } { switch (courage) { case -2: case -1: cout << "You dont have a very courageous personality, get some guts and live your life." << endl; break; case 0: cout << "You have an average amount of courage in your personality, be a little more brave and try new things." << endl; break; case 1: case 2: cout << "You have a courageous personality, good job, you are a cool person." << endl; } } cout << endl; cout << endl; int talkative; char answer5; talkative = 0; cout << " #5 " << endl << "You are at the mall and you see someone you know while you are with your parents." << endl << " What do you do? (A, B, C)" << endl; cout << "A) Stop and talk to them." << endl; cout << "B) Wave discreetly." << endl; cout << "C) Act like you don't know them." << endl; cin >> answer5; if(answer5=='A' || answer5=='a') { talkative = talkative +1; overall = overall +1; } if(answer5=='B' || answer5=='b') { talkative = talkative +0; overall = overall +0; } if(answer5=='C' || answer5=='c') { talkative = talkative -1; overall = overall -1; } char answer6; cout << " #6 " << endl << "Its your first day of school, do you... (A, B, C)" << endl; cout << "A) Try to talk to new people in all your classes." << endl; cout << "B) Only talk to those people that you know." << endl; cout << "C) Sit in the back hoping no one will bother you." << endl; cin >> answer6; if(answer6=='A' || answer6=='a') { talkative = talkative +1; overall = overall +1; } if(answer6=='B' || answer6=='b') { talkative = talkative +0; overall = overall +0; } if(answer6=='C' || answer6=='c') { talkative = talkative -1; overall = overall -1; } { switch (talkative) { case -2: case -1: cout << "You aren't very talkative, try opening your mouth some more... if you are a girl and you got this score, you should seek professional help." << endl; break; case 0: cout << "You are an average talker, nothing special, work on it." << endl; break; case 1: case 2: cout << "You talk a lot, so you are either a girl, or just a guy who can actually hold a convo." << endl; } } cout << endl; cout << endl; int friendly; char answer7; friendly = 0; cout << " #7 " << endl << "You just moved to a new town and see some kids playing outside, do you... (A, B, C)" << endl; cout << "A) Go out, make friends, and play with them." << endl; cout << "B) Go outside and watch them play and hope they ask you to join." << endl; cout << "C) Stay inside." << endl; cin >> answer7; if(answer7=='A' || answer7=='a') { friendly = friendly +1; overall = overall +1; } if(answer7=='B' || answer7=='b') { friendly = friendly +0; overall = overall +0; } if(answer7=='C' || answer7=='c') { friendly = friendly -1; overall = overall -1; } char answer8; cout << " #8 " << endl << "Its a Friday night and you are home, what do you do? (A, B, C)" << endl; cout << "A) Call your friends and meet up with them somewhere." << endl; cout << "B) Surf the net and talk online." << endl; cout << "C) Go to sleep." << endl; cin >> answer8; if(answer8=='A' || answer8=='a') { friendly = friendly +1; overall = overall +1; } if(answer8=='B' || answer8=='b') { friendly = friendly +0; overall = overall +0; } if(answer8=='C' || answer8=='c') { friendly = friendly -1; overall = overall -1; } { switch (friendly) { case -2: case -1: cout << "You aren't very friendly, i dont think a lot of people like you." << endl; break; case 0: cout << "You friendly to those you know, broaden your horizons." << endl; break; case 1: case 2: cout << "You are very friendly! Get a job at Friendly's and remember to smile." << endl; } } cout << endl; cout << endl; int shy; char answer9; shy = 0; cout << " #9 " << endl << "A party is being thrown by someone you really dont know. Do you... (A, B, C)" << endl; cout << "A) Go to the party and talk to anyone and everyone." << endl; cout << "B) Go to the party only if your best friend will be there." << endl; cout << "C) Dont go to the party." << endl; cin >> answer9; if(answer9=='A' || answer9=='a') { shy = shy +1; overall = overall +1; } if(answer9=='B' || answer9=='b') { shy = shy +0; overall = overall +0; } if(answer9=='C' || answer9=='c') { shy = shy -1; overall = overall -1; } char answer10; cout << " #10 " << endl << "Your parents decide to throw you a surprise birthday party. You... (A, B, C)" << endl; cout << "A) Hope everyone you know will be there." << endl; cout << "B) Hope only your closest friends will be there." << endl; cout << "C) Hope they forgot to send out the invitations." << endl; cin >> answer10; if(answer10=='A' || answer10=='a') { shy = shy +1; overall = overall +1; } if(answer10=='B' || answer10=='b') { shy = shy +0; overall = overall +0; } if(answer10=='C' || answer10=='c') { shy = shy -1; overall = overall -1; } { switch (shy) { case -2: case -1: cout << "You are very shy, try to build up some courage and do things you wouldnt normally do." << endl; break; case 0: cout << "You are shy in situations when it has to do with people you dont know, work on that." << endl; break; case 1: case 2: cout << "You are not shy at all, good job, you are a cool person." << endl; } } cout << "Your total score out of 10 was " << overall << endl; return 0; double results (double overall) { overall = shy + courage + friendly + talkative + outgoing; } return 0; } ERROR MESSAGE C:\Documents and Settings\g00s3y\Desktop\final project\final\final.cpp(322) : error C2601: 'results' : local function definitions are illegal and if there are any other errors you guys see please point them out thank you |
|
#2
|
||||
|
||||
|
You're not passing shy, courage, friendly, etc., to the function, but you're attempting to use them. I'm no c++ expert, but that seems like a potential problem area to me. Hmm, it also looks like you're trying to nest the results() function within another, which to my knowledge isn't possible in c++.
__________________
Please don't PM me asking for solutions outside the scope of a thread. Keeping all responses in a thread stands to help others who come along later, which is after all what this forum's all about. |
|
#3
|
|||
|
|||
|
i would have to agree... you really need to pass in those variables. as well as....
this set of code near the end: Quote:
needs to look like this: } cout << "Your total score out of 10 was " << overall << endl; return 0; } double results (double overall) { overall = shy + courage + friendly + talkative + outgoing; } return 0; } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Trouble with a function, please help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|