Why Wont my If Work

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2006
Posts: 8
Reputation: ZenaNqld is an unknown quantity at this point 
Solved Threads: 0
ZenaNqld's Avatar
ZenaNqld ZenaNqld is offline Offline
Newbie Poster

Why Wont my If Work

 
0
  #1
Apr 14th, 2006
New Problem... it keeps outputting both under and over par grrrrrrrrrr
whats wrong with my if statement??!!

  1.  
  2. if (StrokeCount == 5 )
  3. {
  4. cout<< "You are on Par Way To Go!!"<<endl;
  5. cout << endl;
  6.  
  7. }
  8. else
  9. if (StrokeCount < 5)
  10.  
  11. {
  12. Par = 5%StrokeCount;
  13. cout <<" You are "<< Par <<" under Par" << endl;
  14. cout << endl;
  15. }
  16. else
  17. if (StrokeCount > 5 )
  18.  
  19. Par = StrokeCount%5;
  20.  
  21. cout <<" You are "<< Par <<" over Par" << endl;
  22. cout << endl;
Too scared to show my code in case its laughable :o
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1463
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Why Wont my If Work

 
0
  #2
Apr 14th, 2006
you forgot to block in the code for the last if statement.
               if (StrokeCount > 5 ) 
             { 
			    
					Par = StrokeCount%5;
				
				cout <<" You are "<< Par <<" over Par" << endl;	
				cout << endl;
             } 
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 8
Reputation: ZenaNqld is an unknown quantity at this point 
Solved Threads: 0
ZenaNqld's Avatar
ZenaNqld ZenaNqld is offline Offline
Newbie Poster

Re: Why Wont my If Work

 
0
  #3
Apr 14th, 2006
It's always something simple isnt it!!! thanx!
Too scared to show my code in case its laughable :o
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Why Wont my If Work

 
0
  #4
Apr 14th, 2006
	
if (StrokeCount == 5 )
{
			cout<< "You are on Par Way To Go!!"<<endl;
			cout << endl;

}
else
if (StrokeCount < 5)
		
			{
				Par = 5%StrokeCount;
				cout <<" You are "<< Par <<" under Par" << endl;
				cout << endl;
			}
			else
                if (StrokeCount > 5 ) 
			    {
					Par = StrokeCount%5;
				
				cout <<" You are "<< Par <<" over Par" << endl;	
				cout << endl;
}
You need the brackets. Also since you are checking above for StrokeCount == 5 and StrokeCount < 5 no need to check again for StrokeCount > 5. Just a simple else will do but I didnt change that since it works this way also. You can change it if you want.

What did I tell you about the Tabs and Spaces?It is difficult to read code like this. All the formatting is lost.
バルサミコ酢やっぱいらへんで
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC