| | |
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:
Solved Threads: 0
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..
Thanks for looking... :cheesy:
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..
C Syntax (Toggle Plain Text)
char barometer; char rainfall; printf ( "Please enter barometer reading" ); scanf ( "%s", &barometer ); printf ( "Did it rain yesterday?" ); scanf ( "%s", &rainfall ); if ( barometer == storm ) { printf ( "he wears overcoat and hat\n" ); } if ( barometer == rain ) { printf ( "he wears raincoat and takes an umbrella\n" ); } if ( barometer == fair ) { printf ( "he wears light over-jacket and takes an umbrella\n" ); } if ( barometer == very dry) { printf ( "he wears light over-jacket\n" ); } if (( barometer == change ) && ( rainfall == yes )) { printf ( "%s\n", fair ); } if (( barometer == change ) && ( rainfall == no )) { printf ( "%s\n", rain ); } exit(0); }
Thanks for looking... :cheesy:
Last edited by WolfPack; Oct 17th, 2006 at 6:21 pm. Reason: Added [code][/code] tags
>>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.
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]
%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.
C Syntax (Toggle Plain Text)
char rainfall[2]; // 1 byte for either Y or N and secnd byte for null terminator 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.
Also, you probably want to compare barometer to a range, rather than a specific value. Perhaps something like:
The ranges will be determined as the lowest category the barometer value fits into, and by using
C Syntax (Toggle Plain Text)
// assuming storm is low, and better weather is higher if(barometer <= storm) // ... else if(barometer <= rain) // ... else if(barometer <= fair) /* etc... */
else if you won't have conflicts. ![]() |
Similar Threads
- Corrupt registry unable to boot up (Windows 95 / 98 / Me)
- Modem Connected But unable to Browse (Web Browsers)
- Help! Unable to ping machine on the network (Windows NT / 2000 / XP)
- Internet Explorer unable to redirect website! (Web Browsers)
- Unable to get virus definition data (Windows NT / 2000 / XP)
- Unable to get Hard drive to boot ???? (Storage)
- file unable to open (C++)
Other Threads in the C Forum
- Previous Thread: Guid me...If u can
- Next Thread: Help with C in PIC
Views: 1253 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer lazy linked linkedlist linux linuxsegmentationfault list logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat openwebfoundation pattern pause pdf pointer pointers posix power problem program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming spoonfeeding stack standard strchr string strings structures student suggestions system test testautomation unix urboc user voidmain() win32 win32api windows.h






