#include <iostream> 
#include <string> 
using namespace std; 
char *goodmsg = " I feel fine today \n"; 
string badmsg = "I am not feeling well today \n" ; 
 
int main(){ 
 
//prototype definition 
void printMessage( bool ); 
 
//objects declaration 
bool isFine; 
bool &isGood = isFine; 
char *answer = 'y'; 
 
//while loop will repeat executing until user inputs other 
//than y or Y 
while ( answer =='y' || answer=='Y' ){ 
cout <<" How are you today ?" << endl 
<<" If you feel good, answer 1 or else, answer 0 \n"; 
 
//request user input about his feeling 
cin >> isFine ; 
 
//print message according to user input 
printMessage( isGood ); 
 
cout << "Another try (y/n) ?" ; 
cin >> &answer;
} 
return 0; 
} 
 
void printMessage( void isGood ) { 
if ( isGood ) 
cout << goodmsg << endl; 
else 
cout << &badmsg << endl; 
return ; 
}

line 10: that is a function prototype and should appear outside any function, such as on line 6.

And the parameters in the function prototype on line 10 doesn't match the parameters in the actual function on line 35. The two must match exactly.

Why do I get the feeling this is what your tutor wrote to test YOUR error fixing skills?
I mean, what IS THE POINT if you just copy/paste it to a forum.

FFS, put the code in your code editor, and try and fix the problems yourself, otherwise you'll never figure it out.

Sure, if you get stuck and generally confused about what a particular error message means, then that's something worth asking.

But sheesh, just dumping your assignment with "fix it", c'mon man!

Hi, I like the idea here, especially as you are keeping the bulk of your code away from main!
your idea is sound, its just that like the rest of us (well mea anyway) you have dived in without the planning, My only suggestions would be to comment what you want the program to do, first; then code it, this helps you to draw a mental picture of the order of the program, so that debugging is a little easier.

My first point would be the function from line 35 to 40 you have declared type void, but you are trying to return something as you have put a 'Return' in but with nothing to return, so if you did not mean to return anything as I believe, then remove the word Return from line 40;

my second point would be, did you mean to use void in the function header on line 35 where you have (void isGood), i am guessing that you may have ment bool? by the fact that you have declared the definition for this function earlier as bool.

my next point is how you are getting the user input, I can see that you are using pointers, I can only assume this is so that you can practice using them, which is fine, if not I would suggest using standard variables.

Take a look at your declaration for 'char goodmsg' is what you are trying to put into goodmsg a char or a string and change accordingly.

I would advise that you write out you coments before you write the code as this helps me to get the order correct in my head before coding, this will help in the case of lines 27 and 30, line 27 you send print message isGood and it is always going to be true as the user has not yet answered the question and the users answer is never sent to the printmessage function. as you get the user answer and store it in answer but do not send it to the printmessage.

this is one of my most common form of errors, I know what I want the program to do, but the program does not do what I want because I do not tell it to do things in the right order.

My advice about learning to use pointers is to get a program working without them then substitute one variable at a time to become a pointer, that way you can identify where things went wrong fairly easily. you can even write your functions and test them individually by calling the functions from main one at a time.

here is my working code for this sample without the use of pointers because I still need to get to grips with them again!

Hope this newby helped you out a little!

Regards,

Dave

#include "stdafx.h"


#include <iostream> 
#include <string> 
using namespace std; 
string goodmsg = " I feel fine today \n"; 
string badmsg = "I am not feeling well today \n" ; 
 //prototype definition 
void printMessage( bool ); 

int main(){ 
//objects declaration 
bool isFine = true; 
char answer = 'y'; 
 
//while loop will repeat executing until user inputs other 
//than y or Y 
while ( answer =='y' || answer=='Y' ){ 
cout <<" How are you today ?" << endl 
<<" If you feel good, answer 1 or else, answer 0 \n"; 
 
//request user input about his feeling 
cin >> isFine ; 
 
//print message according to user input 
printMessage( isFine ); 
 
cout << "Another try (y/n) ?" ; 
cin >> answer;
} 
return 0; 
} 
 
void printMessage( bool isGood ) { /** you have declared isGood here so you don't need to declare it anywhere else, try and keep functions to themselves, meaning that the function will work as long as the right datatype is sent to it when called, and it is not using global variables, this will help your compiler to identify the error for you.**/
if ( isGood ) 
cout << goodmsg << endl; 
else 
cout << badmsg << endl; 
}
This article has been dead for over six months. Start a new discussion instead.