Unable to see the wood for the trees...

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2006
Posts: 17
Reputation: kissiwat is an unknown quantity at this point 
Solved Threads: 0
kissiwat kissiwat is offline Offline
Newbie Poster

Unable to see the wood for the trees...

 
0
  #1
Oct 17th, 2006
What am I trying to establish here... jolly good question :eek:

Pretty simple piece of code really but can I get this wretched thing to do as its asked - can I as heck...

All it needs to do is display the type of clothing to be worn in certain weather. Anyway here goes..

  1. char barometer;
  2. char rainfall;
  3.  
  4. printf ( "Please enter barometer reading" );
  5. scanf ( "%s", &barometer );
  6.  
  7. printf ( "Did it rain yesterday?" );
  8. scanf ( "%s", &rainfall );
  9.  
  10. if ( barometer == storm )
  11. {
  12. printf ( "he wears overcoat and hat\n" );
  13. }
  14. if ( barometer == rain )
  15. {
  16. printf ( "he wears raincoat and takes an umbrella\n" );
  17. }
  18. if ( barometer == fair )
  19. {
  20. printf ( "he wears light over-jacket and takes an umbrella\n" );
  21. }
  22. if ( barometer == very dry)
  23. {
  24. printf ( "he wears light over-jacket\n" );
  25. }
  26. if (( barometer == change ) && ( rainfall == yes ))
  27. {
  28. printf ( "%s\n", fair );
  29. }
  30. if (( barometer == change ) && ( rainfall == no ))
  31. {
  32. printf ( "%s\n", rain );
  33. }
  34. exit(0);
  35. }

Thanks for looking... :cheesy:
Last edited by WolfPack; Oct 17th, 2006 at 6:21 pm. Reason: Added [code][/code] tags
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,647
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: 1498
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: Unable to see the wood for the trees...

 
0
  #2
Oct 17th, 2006
>>scanf ( "%s", &rainfall );

%s wants a character array of at least 2 bytes. rainfall is not a character array, so the above will always fail to work correctly.
  1. char rainfall[2]; // 1 byte for either Y or N and secnd byte for null terminator
  2. scanf ( "%s", &rainfall );

There are probably other problems, but I stopped reading after that line.
[edit]barometer has the same problem. Where do you declare variables storm etc ? Post them too.[/edit]
Last edited by Ancient Dragon; Oct 17th, 2006 at 7:22 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Unable to see the wood for the trees...

 
0
  #3
Oct 17th, 2006
Also, you probably want to compare barometer to a range, rather than a specific value. Perhaps something like:
  1. // assuming storm is low, and better weather is higher
  2. if(barometer <= storm)
  3. // ...
  4. else if(barometer <= rain)
  5. // ...
  6. else if(barometer <= fair)
  7. /* etc... */
The ranges will be determined as the lowest category the barometer value fits into, and by using else if you won't have conflicts.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 1253 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC