Question: C exercise - Define a menu function dispMenu (defined below) which will let the user select which exercise to demo. The user can quit with

C exercise -

Define a menu function dispMenu (defined below) which will let the user select which exercise to demo. The user can quit with q or Q. The user can stay within a particular exercises function until they quit with a sentinel code that you choose.

// returns menu choice 1 to n. Define n choices for now. You can change n to whatever you need it to be. int dispMenu();

Demo functions////////////////

/////////////create as a function1

#include #include

int main(){

float x,y; int n;

for(n=1;n<=5;n++){

printf("enter any decimal value: "); scanf("%f",&x); y=floor(x+.5); printf ("the round-off of %.2f is %.lf ",x,y); }return 0; }

/////////

//////////////create function 2

#include

int iseven(int number);

int main(){

int number;

printf("enter a series of integers, end with 0: ");

scanf("%d",&number); printf(" "); while (number!=0){ if (iseven(number)) printf("%d is an even number. ",number); else printf("%d is an odd number. ",number); scanf("%d",&number);} return 0; }

int iseven(int number)

{ if (number%2==0) return 1; else return 0; } ////////////creating function 3

#include

int celsius(int fCurrent); int fahrenheit(int cCurrent);

int main(){ int x; printf("celsius to fahrenheit conversion table: "); printf("celsius \t\tFahrenheit ");

for(x=0;x<=100;x++){ printf("%d\t\t%d ",x,fahrenheit(x));

} printf("Fahrenheit to celcius conversion table: "); printf("fahrenheit celcius "); for( x=32;x<=212;x++){

printf("%d\t\t%d ",x,celcius(x)); }

return 0; }

int celcius (int fCurrent){ return (int)(5.9/9.0*(fCurrent-32));}

int fahrenheit(int cCurrent){ return (int)(9.0/5.0*cCurrent+32);}

////////////creating function 4

int main() { double x; printf("Enter number to round: "); scanf_s("%lf", &x); printf(" Number: %lf Rounded to integer: %.0lf Rounded to nearest tenth: %.1lf Rounded to nearest hundredth: %.2lf Rounded to nearest thousandth: %.3lf ", x, roundToInteger(x), roundToTenths(x), roundToHundreths(x), roundToThousandths(x));

return 0; }

double roundToInteger(double number) { return floor(number + .5); } double roundToTenths(double number) { return floor(number * 10 + .5) / 10; } double roundToHundreths(double number) { return floor(number * 100 + .5) / 100; } double roundToThousandths(double number) { return floor(number * 1000 + .5) / 1000; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!