View the step-by-step solution to:

Question

1.jpg2.jpg

my code

when I prompt N or n at 'Would like to continue?' but my program not break, it still running.I want to know my mistake in this my code.I want the output same pic1.

1.jpg

Please enter radius and height of a cylinder: 3 4
The volume of the cylinder is 113.097
Would like to continue? Y
Please enter radius and height of a cylinder: 6 -5
Invalid input. Try again.
Please enter radius and height of a cylinder: 7
The volume of the cylinder is 307.876
Would like to continue? N
Good bye !

2.jpg

C:\Users\ Test\ Desktop\Com Pro#1\Lab#9 (2).cpp - [Executing] - Dev-C+ + 5.11
X
File Edit Search View Project Execute Tools AStyle Window Help
TDM-GCC 4.9.2 64-bit Release
1 10 (globals
v
Project Classes Debug
[*] Lab#9 (2).cpp
JOUPUNK
#include <iostream>
#include <iomanip>
using namespace std;
C:\Users\Test\ Desktop\Com Pro#1\Lab#9 (2).exe
-
X
float volume(float radius, float height);
lease enter radius and height of a cylinder: 3 4
int main( ) {
The volume of the cylinder is 113. 112
float r,h;
Would like to continue? y
8
float num=0;
Please enter radius and height of a cylinder: 6 -5
9
char c, n, N, y, Y;
Invaild input. Try again.
10 -
while (num<=0 ){
Please enter radius and height of a cylinder: 4 6
11
12
cout << "Please enter radius and height of a cylinder: ";
The volume of the cylinder is 301. 632
Would like to continue? n
13
cin > > r;
cin > > h;
Good bye!
14
15
if(r <= -1 | | h <= -1 ){
cout << "Invaild input. Try again. \n";
Please enter radius and height of a cylinder:
16
Jelse{
17
18
cout << "The volume of the cylinder is " << fixed << setprecision(3) << volume(r,h);
cout << "\nWould like to continue? ";
19
cin >> c;
20
21
switch(c){
22
case 'n' :
cout << "Good bye!\n";
23
break;
case 'N' :
cout << "Good bye!\n";
break;
31 float volume(float radius, float height) {
return 3.142* radius* radius * height;
up Compiler Resources lli Compile Log Debug [ Find Results $3 Close
Abort Compilation
Warnings: 0
Output Filename: C: \Users\Test\Desktop\Com Pro#1\Lab#9 (2) . exe
Output Size: 1. 83487033843994 MiB
Compilation Time: 0. 69s
Shorten compiler paths
13
Col: 18
Sel:
0
Lines: 33
Length: 734
Insert
Done parsing in 0 seconds

Top Answer

Your program is not exiting after preesing n or N is because you are using switch... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question