Q BgQuestion:

      
Rookie
Karma Points: 10
Respect (92%):
posted by  Nrk on 11/7/2009 2:33:17 AM  |  status: Closed  |  Earned Karma: 10

C programing help required urgent!

Course Textbook Chapter Problem Needs by
N/A N/A N/A N/A 11/7/2009 at 11:00:00 AM
Question Details:

Write a program in C language using switch statement & while loop that 
finds density, pressure by the following formula
1.d=m/v
2.
i.e the program should ask user to enter numbers
if user want to find density press 1 or if user want to find pressure press2
if user  want to exit press3
Good

AAnswers:

Answer Question Ask for clarification
Rookie
Karma Points: 10
posted by Nrk on 11/7/2009 9:29:37 AM  |  status: Live
Asker's Rating: N/A-Posted by Person Asking Question   
Response Details:
#include <stdio.h>
#include<conio.h>
int main()
{double d,m,v,v2,p1,p2;
int num;
clrscr();
printf("Do you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit\n");
scanf("%d",&num);
while(num!=3)
{
switch(num)
{case 1:printf("\nEnter the value for m: ");
        scanf("%lf",&m);
        printf("Enter the value for v: ");
        scanf("%lf",&v);
        printf("The density is %lf\n", m/v);
        break;
        
 case 2:printf("\nEnter the value for p1: ");
        scanf("%lf",&p1);
        printf("Enter the value for v1: ");
        scanf("%lf",&v);
        printf("Enter the value for v2: ");
        scanf("%lf",&v2);
        printf("The pressure is %lf\n", (p1*v)/v2);
        break;
default: printf("Invalid Input-program aborted\n");
}
printf("\nDo you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit\n");
scanf("%d",&num);
}
return 0;
}
Good
Oracle
Karma Points: 31,807
posted by rapunzel on 11/7/2009 9:49:39 AM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
please rate - thanks

1 version

#include <stdio.h>
#include<conio.h>
int main()
{double d,m,v,v2,p1,p2;
int num;
printf("Do you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit");
scanf("%d",&num);
switch(num)
{case 1:printf("Enter the value for m: ");
        scanf("%lf",&m);
        printf("Enter the value for v: ");
        scanf("%lf",&v);
        printf("The density is %lf\n", m/v);
        break;
        
 case 2:printf("Enter the value for p1: ");
        scanf("%lf",&p1);
        printf("Enter the value for v1: ");
        scanf("%lf",&v);
        printf("Enter the value for v2: ");
        scanf("%lf",&v2);
        printf("The pressure is %lf\n", (p1*v)/v2);
        break;
case 3: return 0;
 default: printf("Invalid Input-program aborted\n");
}
getch();
return 0;
}


2nd version-keeps looping


#include <stdio.h>
#include<conio.h>
int main()
{double d,m,v,v2,p1,p2;
int num;
printf("Do you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit\n");
scanf("%d",&num);
while(num!=3)
{
switch(num)
{case 1:printf("\nEnter the value for m: ");
        scanf("%lf",&m);
        printf("Enter the value for v: ");
        scanf("%lf",&v);
        printf("The density is %lf\n", m/v);
        break;
        
 case 2:printf("\nEnter the value for p1: ");
        scanf("%lf",&p1);
        printf("Enter the value for v1: ");
        scanf("%lf",&v);
        printf("Enter the value for v2: ");
        scanf("%lf",&v2);
        printf("The pressure is %lf\n", (p1*v)/v2);
        break;
default: printf("Invalid Input-program aborted\n");
}
printf("\nDo you want to find density or pressure?\n");
printf("1 to find density\n2 find pressure\n3 exit\n");
scanf("%d",&num);
}
return 0;
}




Note to all members 1. Please 1 question per post 2. Show respect to your fellow members by rating all answers. 3. When rating remember that the first answer is not necessarily the best answer. 4. When answering questions, explain what you are doing, so that the asker will learn, don't just give a meaningless number. 5. Your answers should be your work. Don't copy from another member, this is Karma abuse and possible disciplinary actions against you. and GOOD LUCK to you all!!
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »