Results 1 to 14 of 14

Thread: Newb: How does this look

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Comreak's Avatar
    Join Date
    Feb 2001
    Location
    Dis
    Posts
    319

    Newb: How does this look

    I just put this together for my C++ class. I've tested it thoroughly but I want to make sure I'm doing everything correctly. Tell me if you see anything that doesn't stick to standards or whatever. By the way, this is supposed to check the difference between the ages of two people. Thanks for your time.

    PS - You'll probably notice some strange things about the code. For instance, I chose to put std:: in front of cout and cin. This was intentional (part of the requirements for this particular exercise).


    Code:
    #include <iostream>
    #include <stdlib.h>
    
    typedef unsigned short int USHORT;
    
    int main()
    {       
    		char FirstPersonName[40];
    		char SecondPersonName[40];
    		USHORT FirstPersonAge;
    		USHORT SecondPersonAge;
    		USHORT AgeResult;
    		std::cout << "This program calculates the age difference between two people. \n\n";
    		
    		std::cout << "What is the name of the first person? \n";
    		std::cin >> FirstPersonName;
    		std::cout << "How old is " << FirstPersonName << "? \n";
    		std::cin >> FirstPersonAge;
    		
                                    std::cout << "What is the name of the second person? \n";
    		std::cin >> SecondPersonName;
    		std::cout << "How old is " << SecondPersonName << "? \n";
    		std::cin >> SecondPersonAge;
    		
    		if (FirstPersonAge == SecondPersonAge)
    		{
    			std::cout << "Result: " << FirstPersonName << " and " << SecondPersonName << " are the same age. \n";
    			system("pause");
                                                    exit(0);
    		}
    		
    		if (FirstPersonAge > SecondPersonAge)
    		{
    			AgeResult = FirstPersonAge - SecondPersonAge;
    			std::cout << "Debug AgeResult: " << AgeResult << "\n";
    
    			if (AgeResult == 1)
    			{
    					std::cout << "Result: " << FirstPersonName << " is " << AgeResult << " year older than " << SecondPersonName << ". \n";
    			}
    			else
    			{
    					std::cout << "Result: " << FirstPersonName << " is " << AgeResult << " years older than " << SecondPersonName << ". \n";
    			}
    		}
    		else
    		{	
    			AgeResult = SecondPersonAge - FirstPersonAge;
    
    			if (AgeResult == 1)
    			{
    							std::cout << "Result: " << SecondPersonName << " is " << AgeResult << " year older than " << FirstPersonName << ". \n";
    			}
    			else
    			{
    							std::cout << "Result: " << SecondPersonName << " is " << AgeResult << " years older than " << FirstPersonName << ". \n";
    			}
    		}
    		system("pause");
    		return 0;
    }
    Last edited by Comreak; Feb 6th, 2003 at 05:48 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width