1
Independent Study Projects / Planetary Weight Computer System ... haha... Still learning C
« on: March 05, 2009, 05:11 AM »
HELLO.
This is due in my CIS C Programming class soon. I thought it would be no sweat, but I ran into some trouble at the end because I cannot break out of a switch when the switch/case is inside of a while loop. If you have any code suggestions please let me know. I probably went about it wrong. Maybe I should have used a flowchart or something.
ok. whatever.. have a look. thanks.
This is due in my CIS C Programming class soon. I thought it would be no sweat, but I ran into some trouble at the end because I cannot break out of a switch when the switch/case is inside of a while loop. If you have any code suggestions please let me know. I probably went about it wrong. Maybe I should have used a flowchart or something.
ok. whatever.. have a look. thanks.
Code: C [Select]
- #include <stdio.h>
- void moon(double dEarthWeight);
- void mars(double dEarthWeight);
- void jupiter(double dEarthWeight);
- void err_msg(int error);
- int main( void )
- {
- char cPlanetSelect, cDoLoop = 'y';
- double dEarthWeight;
- do
- {
- if ( dEarthWeight <= -1 )
- {
- err_msg( 1 );
- continue;
- }
- && cPlanetSelect != 'Y'
- && cPlanetSelect != EOF )
- {
- switch ( cPlanetSelect )
- {
- case 'm':
- case 'M':
- moon( dEarthWeight );
- break;
- case 'r':
- case 'R':
- mars( dEarthWeight );
- break;
- case 'j':
- case 'J':
- jupiter( dEarthWeight );
- break;
- case '\n':
- case '\t':
- case ' ':
- case 'y':
- case 'Y':
- break;
- case 'n':
- case 'N':
- return ( 0 );
- break;
- default:
- err_msg( 2 );
- break;
- }
- }
- /* printf("\nDo you want to check your weight on a different planet? (Y/N): ");
- scanf("%c", &cDoLoop);
- if ( cDoLoop != 'y' && cDoLoop != 'n')
- scanf("%c", &cDoLoop); */
- }
- while ( cDoLoop != 'n' || cDoLoop == 'N' );
- return ( 0 );
- }
- void moon(double dEarthWeight)
- {
- return;
- }
- void mars(double dEarthWeight)
- {
- return;
- }
- void jupiter(double dEarthWeight)
- {
- return;
- }
- void err_msg(int error)
- {
- if ( error == 1)
- else
- {
- }
- return;
- }