Jump to content
  • Advertisement
Sign in to follow this  
Inuyashakagome16

HELP!.....again

This topic is 4652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok....Tell me what i did wrong in this program. All i tried to do is make a conversation program. u know where i can talk back and forth with the computer.
#include <iostream>	

using namespace std;
int mult (int age, int good, int bad ); 		
int main()                           
{
  int age;
  int good;
  int bad;                         

  cout<<"Please input your age: ";    
  cin>>age;                         
  cin.ignore();                       
  if ( age < 100 ) {                 
     cout<<"You are pretty young!\n";
  }
  else if ( age == 100 ) {           
     cout<<"You are old\n";           
  }
  else {
    cout<<"You are really old\n";    
  }
  cout<<"How are you today?:";
  cin>>good;
  if (good < good) {
     cout<<"Good. I am good as well!\n";
  }
  else if ( good == bad) {
       cout<<"Aww what is the matter?";
  }
  else {
    cout<<"???";
 cin.get();
}

Share this post


Link to post
Share on other sites
Advertisement
Perhaps you could describe the problem? What does it do that you don't want it to? Or what does it not do that you do want it to? At least give us a clue to what we're looking for.

Share this post


Link to post
Share on other sites
k. after u answer the question of how old u are, it goes to How are u today. and when i put good or bad. it closes the program. maybe someone else can compile it and they will see what it does.

C:\Documents and Settings\\Desktop\hello.cpp In function `int main()':
34 C:\Documents and Settings\\Desktop\hello.cpp expected `}' at end of input

Share this post


Link to post
Share on other sites
Quote:
  if (good < good) {
cout<<"Good. I am good as well!\n";
}
else if ( good == bad) {
cout<<"Aww what is the matter?";
}


good < good will always be false because good is an int.
good == bad will compare the int good to the int bad. bad is uninitialized, so it sure isn't going to do what you want.

Are you looking for strings?

#include <string>

...

string good;

...

if (good == "good")

...

else if (good == "bad")


Also, you forgot a closing brace after cout<<"???";

Share this post


Link to post
Share on other sites
EDIT: sweet, merciful crap! You guys move fast while I'm typing!


I'm not sure what your problem is. Did you have warnings, errors, linker errors?

When you post code, try putting it in [ source ] put code here! [ /source ] That will keep your spacing and make your code more readable.

As far as I can tell, int good and int bad don't mean anything. If the program gets to "How are you today?" Are you entering a number or a character or what? int is an integer, and only accepts numbers.

Then, you compare the int "good" to the int "bad", which doesn't have anything in it yet. You shouldn't use variables that haven't had anything put into them yet.

You might want to consider making "good" and "bad" into character arrays or strings. I would, instead, make the question into a yes or no, then give a list of multiple-choice responses, and have them pick a number of an appropriate response.

I'm sorry if this doesn't help much, but I'm a bit confused as to what you're looking for.

Try the tutorials at cplusplus.com, they teach beginning to intermediate concepts fairly well.

Share this post


Link to post
Share on other sites
Quote:
Original post by templewulf
Try the tutorials at cplusplus.com, they teach beginning to intermediate concepts fairly well.



A good book would come much more highly recommended than learning C++ at cplusplus.com.

As an example of why it is bad to learn from cpluplus.com, take a look at their first tutorial here.


The example code given does not conform to many areas of the C++ standard.



// my first program in C++

#include <iostream.h>

int main ()
{
cout << "Hello World!";
return 0;
}




The header iostream.h does not exist in the C++ standard, so including it isn't likely to compile.

The cout object is in the std namespace in standard c++, and so the namespace must be qualified somewhere, with either an std:: or a 'using' statement.

Also the cout object needs to have the <ostream> header included when invoking its operator<< member functions, and so it should really be explicitly included (the iostream header is not required to include it by the standard).

A better learning resource would be Accelerated C++.

Share this post


Link to post
Share on other sites
here is the reformed version.

#include <iostream>
#include <string.h>
using namespace std;
int age;
char good;
int main ()
{

int age;
char good;
char bad;

cout << "Please input your age: ";
cin >> age;
cin.ignore();
if ( age < 100 ) {
cout << "You are pretty young!\n";
}
else if ( age == 100 ) {
cout << "You are old\n";
}
else {
cout << "You are really old\n";
}
cout << "How are you today?:";

if (good == "good") {
cout << "Good. I am good as well!\n";
}
else if ( good == "bad") {
cout << "Aww what is the matter?";
}
else {
cout << "???";
}
return 0;
}




and here are the errors:
C:\Documents and Settings\\Desktop\hello.cpp In function `int main()':

27 C:\Documents and Settings\\Desktop\hello.cpp ISO C++ forbids comparison between pointer and integer

30 C:\Documents and Settings\\Desktop\hello.cpp ISO C++ forbids comparison between pointer and integer


im still confused. i went to the C++ tutorial and im still.

Share this post


Link to post
Share on other sites
ok. i dont know what i did, but now when i put in my age it closes the program. Any ideas?
Or Tips?
#include <iostream>
#include <string>
using namespace std;
int age;
string good;
string bad;
int main ()
{

int age;
string good;
string bad;

cout << "Please input your age: ";
cin >> age;
cin.ignore();
if ( age < 100 ) {
cout << "You are pretty young!\n";
}
else if ( age == 100 ) {
cout << "You are old\n";
}
else {
cout << "You are really old\n";
}
cout << "How are you today?:";

if (good == "good") {
cout << "Good. I am good as well!\n";
}
else if ( good == "bad") {
cout << "Aww what is the matter?";
}
else {
cout << "???";
}
}


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!