Thread: Tutorial #2 issue

  1. #1
    C++ newb in training
    Join Date
    Mar 2005
    Location
    Burlington Wa
    Posts
    14

    Tutorial #2 issue

    Hey everyone I posted this the last timei n the wrong forum but any who I altered TuTorial #2 the imput age one and it wont print my answer. I tried something some one pointed out in the other post (for got I went to the Prograsming for windows section) and his suggestion dident work. Here it is. Beaware I am a C++ newb lol

    Code:
    #include <iostream>
    using namespace std;
    int main()						 
    {
    	int age;					 
     
    	cout<<"Please imput your age: ";	
    	cin>> age;					 
    	cin.ignore();
    	if ( age= 13> 49) {
    		 cout <<"Your Young!\n";
    		 }
    	else if ( age= 1> 12) {
    			 cout <<"You are really young!\n";
    			 }
    	else if ( age= 50> 84) {
    			 cout <<"Your getting Old!\n";
    			 }
    	else if ( age= 85> 99) {
    			 cout <<"Your getting real old!\n";
    			 }
    	else if (age= 100> 103) {
    			 cout <<"Damn your still alive!\n";
    			 }
    	else if (age= 104> 10000 ) {
    			 cout <<"Your Dead get over it!\n";
    			 }
     
     
     
     
    cin.get();
    cin.ignore();
     
    }
    Find the loop holes, then fix the errors, after you have found all the useful info

  2. #2
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    Code:
    if ( age= 13> 49) {
    		 cout <<"Your Young!\n";
    		 }
    this doesn't make much sence

    try:
    Code:
    if (age <= 13) {
      cout << "your young!\n";
    }
    do the same for every one

    EDIT:

    o nvm i see what you are trying to do

    Code:
    if( age >= 1 && age <= 12)
    {
       cout << "You are really young" << endl;
    }
    if(age >= 13 && age <= 49)
    {
      cout << "You are young" << endl;
    }
    if(age >= 50 && age <= 84)
    {
      cout << "you are getting old" << endl;
    }
    if(age >= 85 && age <= 99)
    {
      cout << "You are getting realy old" << endl;
    }
    if(age >= 100 && age  <= 103)
    {
      cout << "dam you are still alive" << endl;
    }
    if(age >= 104)
    {
      cout << "You are dead ge over it" << endl;
    }
    Last edited by mrafcho001; 03-20-2005 at 07:12 PM.

  3. #3
    C++ newb in training
    Join Date
    Mar 2005
    Location
    Burlington Wa
    Posts
    14
    sweet I got it to work now. When I added the <<end1; it erroed but I removed that and kept the age >= in and it worked. Thanks alot

    EDIT: how would I make it so it keeps looping after entering the number and getting the result? I tried
    Code:
    return();
    but it dident do anything.
    Last edited by Keiyentai; 03-20-2005 at 07:53 PM.
    Find the loop holes, then fix the errors, after you have found all the useful info

  4. #4
    Registered User mrafcho001's Avatar
    Join Date
    Jan 2005
    Posts
    483
    try

    end; (end small case L not 1)

    and its return 0;

    for looping

    you can put all the code in a while loop

    so it would be something like
    Code:
    #include <iostream>
    #include <stdlib.h>
    using namespace std;
    
    int main()
    {
      int a = 1;
      while (a == 1)
      {
       // all the code 
      }
    
    // this will keep looping untill the user closes the program
      }
    or what he said below it makes more sence mine is just shorted.
    Last edited by mrafcho001; 03-20-2005 at 08:03 PM.

  5. #5
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    ya mean with a while loop?

    Code:
    #include <iostream>
    using namespace std;
    int main()						 
    {
    	int age;
    	char exit;	
    	
    	do
    	{
    							 
    		 
    		cout<<"Please input your age: ";	
    		cin>> age;					 
    		cin.ignore();
    	
    	
    		if( age >= 1 && age <= 12)
    		{	
    		   cout << "You are really young" << endl;
    		}
    		if(age >= 13 && age <= 49)
    		{
    		  cout << "You are young" << endl;
    		}
    		if(age >= 50 && age <= 84)
    		{
    		  cout << "you are getting old" << endl;
    		}
    		if(age >= 85 && age <= 99)
    		{
    		  cout << "You are getting realy old" << endl;
    		}
    		if(age >= 100 && age  <= 103)
    		{
    		  cout << "dam you are still alive" << endl;
    		}
    		if(age >= 104)
    		{
    		  cout << "You are dead ge over it" << endl;
    		}
    	 
    	 
    	 
    	 
    		cin.get();
    		cin.ignore();
    		
    		cout << "Exit Y/N?";
    		cin >> exit;
    	
    	 
    	}while(exit != 'y' || exit != 'Y');
    }
    Last edited by DeepFyre; 03-20-2005 at 08:04 PM.
    Keyboard Not Found! Press any key to continue. . .

  6. #6
    C++ newb in training
    Join Date
    Mar 2005
    Location
    Burlington Wa
    Posts
    14
    Cool thanks guys
    Find the loop holes, then fix the errors, after you have found all the useful info

  7. #7
    People Love Me
    Join Date
    Jan 2003
    Posts
    412
    Also, just a helpful tip:
    Code:
       int x = 5;
    if (x=6)
        cout << "I love you."<<endl;
    It should be noted that this if statement evaluates to true, and will execute. I'm not sure if you really know the difference between = and == just yet, but = assigns the value on the left side of the operator to be that of the right-side operand. == compares two operands without altering them.

  8. #8
    C++ newb in training
    Join Date
    Mar 2005
    Location
    Burlington Wa
    Posts
    14
    Cool Will check it out later. Thanks for the help guys. Really apriciate it. Good to have a forum where some one can ask for some help with out getting flamed.
    Find the loop holes, then fix the errors, after you have found all the useful info

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. Compiling issue with the OpenGL tutorial by RoD
    By Twitchmokey in forum Game Programming
    Replies: 12
    Last Post: 06-26-2006, 06:05 PM
  3. My new website
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 19
    Last Post: 03-17-2006, 07:38 PM
  4. Cprog tutorial: Design Patterns
    By maes in forum C++ Programming
    Replies: 7
    Last Post: 10-11-2004, 01:41 AM
  5. Tutorial review
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 03-22-2004, 09:40 PM