Hi, im having trouble with simple problems with c++ and i just started up. I am trying to Determine what shirt size a person will wear if they weight from 100 - 199 lbs but i just dont know how do run it, the screen goes blank after i type in there weight. heres the code i have so far.

#include <iostream>
 #include <iomanip>
 #include <string>
 using namespace std;
 
 int main()
 {
     //local constants
     const int MIN_WEIGHT=100;
     const int MAX_WEIGHT=199;
      
     //local variables
     int WEIGHT;        //Weight of customer
     float SMALL;       //Shirt Size is Small
     float MEDIUM;      //Shirt Size is Medium
     float LARGE;       //Shirt Size is Large
     float NO_SHIRT;    //No shirt
     
     /***************************start main program*******************/
 
    
     //Input Customers weight
     cout << "Customers weight   :" ;
     cin  >> WEIGHT   ; 
      
     
     //Clear the screen
     system("cls");
     
     if (WEIGHT <=100 && WEIGHT >= 200)
     {
                if (NO_SHIRT)
                {
                (WEIGHT <=100 && WEIGHT >= 200);
                cout << "No Shirt"<<endl;
                //Display NO_SHIRT 
                }
                else if (SMALL)
               {
               (WEIGHT <=135 && WEIGHT >= 100);
                cout << "Small Shirt"<<endl;
                //Display SMALL
                }
                else if (MEDIUM)
                {
                (WEIGHT <=136 && WEIGHT >= 165);
                cout << "Medium Shirt"<<endl; 
                //Display MEDIUM
                }
                else (LARGE);
                {
                (WEIGHT <=166 && WEIGHT >= 199);
                cout << "Large Shirt"<<endl;
                //Display LARGE
                }
     }
     
     //Display Shirt Size 
     //pause the output screen for viewing
     system("pause");
         
     //return 0 to OS
     return 0;
     
}//end main program

Couple o' things:

1) Variables aren't initialized, then they are used (examined) later in the code. You will get unexpected results with this.
2) Your very first comparison ("if (WEIGHT <=100 && WEIGHT >= 200)") is always false. You can't have a weight that is less than 100 and greater than 200 a the same time. This is causing you to drop all the way to the end of your code.
3) In each of your blocks, you are checking the value of an uninitialized variable, before you check the weight of the person to see if they fit in the range.
4) The range checks don't have an "if" in front of them. Also, they have semicolons at the end - that will mess things up.

Try taking a look at those items and see how it goes.

line 14-17: where SMALL, MEDIUM etc defined ?

I think you need to declare just one int variable that can contain the enum variables SMALL, MEDIUM ...

enum sizes {NO_SIZE, SMALL, MEDIUM, LARGE, XLARGE};
    sizes shirt_size = NO_SIZE;

    ...
    if (WEIGHT <=135)
      shirt_size = SMALL;
    else if( WEIGHT <= 165)
      shirt_size = MEDIUM;
   else if( WEIGHT <= 200)
      shirt_size = LARGE;

here is the corrected version :

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
	//local constants
	const int MIN_WEIGHT=100;
	const int MAX_WEIGHT=199;

	//local variables
	int WEIGHT; //Weight of customer
	float SMALL; //Shirt Size is Small
	float MEDIUM; //Shirt Size is Medium
	float LARGE; //Shirt Size is Large
	float NO_SHIRT; //No shirt

	/***************************start main program*******************/


	//Input Customers weight
	cout << "Customers weight :" ;
	cin >> WEIGHT ; 


	//Clear the screen
	system("cls");

	if (WEIGHT >=100 && WEIGHT <= 200)
	{
		
	    if (WEIGHT <=135 && WEIGHT >= 100)
		{
		cout << "Small Shirt"<<endl;
		//Display SMALL
		}
		else if (WEIGHT >=136 && WEIGHT <= 165)
		{
		cout << "Medium Shirt"<<endl; 
		//Display MEDIUM
		}
		else (WEIGHT >=166 && WEIGHT <= 199);
		{
		cout << "Large Shirt"<<endl;
		//Display LARGE
		}
	}
	else
	cout << "No Shirt"<<endl;
		//Display NO_SHIRT 

	//Display Shirt Size 
	//pause the output screen for viewing
	system("pause");

	//return 0 to OS
	return 0;

}//end main program
Comments
Looks very helpful :)

You have errors.

how do you think you are helpful to me or to this guy by saying i have errors and not even mentioning them, you must be around 14 years old kid that i dont even bother to respond.

from now on for every garbage you post related to my posts, i am going to add to your reputation just two words, Rashakil Fool, and your reputation will arise as the time passes, as a successful fool.

line 43: should be else if not just else. And what are you going to use those float variables for? If you aren't going to use them then just delete them.

line 43: should be else if not just else. And what are you going to use those float variables for? If you aren't going to use them then just delete them.

i didnt intend to post perfect version, the one i posted is enough to see where he made the error, what i did is much better than saying "you have errors". the one i posted, compiles and does some operations similar to his goal, so what is wrong?

i didnt intend to post perfect version, the one i posted is enough to see where he made the error, what i did is much better than saying "you have errors".

Agreed. :)

the one i posted, compiles and does some operations similar to his goal, so what is wrong?

It displays two shirt sizes. Large was always displayed, which is why you needed the else if

Agreed. :)

It displays two shirt sizes. Large was always displayed, which is why you needed the else if

i posted that thing within 2 minutes while i was doing what i was assigned to do at work, all the posts that i send during day time is while working, so i may not have noticed that i missed "else" there. helping is helping and must be encouraged and supported, if i miss "else" there some one has to add "else" to my code and post it again as a refined version, it wont offend me, but if someone post something just to satisfy his ego over my mistake, that is bad.

i posted that thing within 2 minutes while i was doing what i was assigned to do at work, all the posts that i send during day time is while working, so i may not have noticed that i missed "else" there. helping is helping and must be encouraged and supported, if i miss "else" there some one has to add "else" to my code and post it again as a refined version, it wont offend me, but if someone post something just to satisfy his ego over my mistake, that is bad.

I'm not trying the badger you, just pointed out that the else is needed in the code you posted. And what are you doing surfing the net while you are supposed to be working ??? Or do you get paid to surf?

I'm not trying the badger you, just pointed out that the else is needed in the code you posted. And what are you doing surfing the net while you are supposed to be working ??? Or do you get paid to surf?

i am not surfing, after continuous thinking of 45 minutes or so my brain stops for a while, to rest that portion of my brain i focus on another thing, which is usually one of the forums in daniweb, other than that i usually post my own questions, which you can not name as surfing.

Comments
We all need that sort of break from work occasionally :)

here is the corrected version :

You have errors.

what are those errors?

but if someone post something just to satisfy his ego over my mistake, that is bad.

All I did was answer your question -- what are those errors, and you get all upset.

All I did was answer your question -- what are those errors, and you get all upset.

He's not mad at you, but at R. Fol. I think they have some sort of business between them, so don't lose any sleep over it :). But I'm getting to far Off/topic

Comments
Thanks for clarifying that :)
This article has been dead for over six months. Start a new discussion instead.