Q BgQuestion:

      
Rookie
Karma Points: 10
Respect (92%):
posted by  Nrk on 11/6/2009 4:35:33 PM  |  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 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: 11
posted by Anonymous on 11/6/2009 5:07:27 PM  |  status: Live
Asker's Rating: Helpful   
Response Details:
double n,m,v,d,p1,p2,v1,v2;
switch (n) {
case 0:
cout<<" wrong no.";
break;
case 1:
cout<<" enter the value of mass :";
cin>>m;
cout<<" enter the value of volume :"
cin>>v;
cout<<" density = "<<d=m/v;
break;
case 2:
cout<<" enter the value of p1 :";
cin>>p1;
cout<<" enter the value of v1 :"
cin>>v1;
cout<<" enter the value of v2 :"
cin>>v2;
cout<<" result = "<<p2=(p1*v1)/v2;
break;
}
Pupil
Karma Points: 81
posted by dropt on 11/6/2009 5:39:46 PM  |  status: Live
Asker's Rating: Helpful   
Response Details:
I don't have a compiler handy to check for errors, but this should work for you.  Let me know if you need some clarification



#include <iomanip>
#include <iostream>


using namespace std;

int main(){                                        //start int Main()
    char choice;
    cout << "Enter a for density or b for volume: ";
    cin >> choice;
    switch(choice){
                   case 'a':
                        float m;
                        float v;
                        cout << "\nEnter the mass: ";
                        cin >> m;
                        cout << "\nEnter the volume: ";
                        cin >> v;
                        float d=m*v;
                        cout << "\nThe density is: ";
                        cout << d;
                        break;

                   case 'b':
                        float p1;
                        float v1;
                        float v2;
                        cout >> "\n Enter p1: ";
                        cin << p1;
                        cout >> "\n Enter v1: ";
                        cin << v1;
                        cout >> "\n Enter v2: ";
                        cin << v2;
                        float p2=(p1*v1)/v2;
                        cout >> "\n The pressure is: ";
                        cout >> p2;
                         break;

                   default:
                         cout >> "\nYou entered an invalid option!";
                         break;
                   }
    return EXIT_SUCCESS;                           //Program finished!
}//end int Main()


Oracle
Karma Points: 31,807
posted by rapunzel on 11/6/2009 8:43:51 PM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
please rate - thanks

#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\n");
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;
 default: printf("Invalid Input-program aborted\n");
}
getch();
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 »