
Register and join over 40,000 other developers!
Recent Topics
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
-
Job Gig PHP Form Needed
PJohnson - Apr 18 2019 03:55 AM
-
How to make code run differently depending on the platform it is running on?
xarzu - Apr 05 2019 09:17 AM
-
How do I set a breakpoint in an attached process in visual studio
xarzu - Apr 04 2019 11:47 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

16 replies to this topic
#13
Posted 23 September 2012 - 01:15 PM
I did I really did try that.

#14
Posted 23 September 2012 - 01:24 PM
can you show me how your code looks like, now after those changes.
#15
Posted 23 September 2012 - 01:26 PM
#include <iostream> #include <iomanip> #include <stdlib.h> #include <cstdlib> #include <process.h> using namespace std; int main() { // contains the variables // variables double AREA; double circle; double Triangle; int Quit; int choice; double pi; //radius pi = 3.14159; double radius; /// rectangle double Rectangle; double area; double number; double length; double width; //triangle double TRIANGLE; double AREA3; double base; double height2; double area2; // quit double WAY2; double answer; char input; char n; //asks the user which one and displays it //constants for menu choices const int CIRCLE_AREA1 = 1, Rectangle_AREA2 = 2, TRIANGLE_AREA3 = 3, QUIT_WAY2 = 4; // display the choices cout << "1. Calculate the Area of a Circle\n\n" << "2. Calculate the area of a Rectangle \n\n" << "3. Calculate the Area of a Triangle \n\n" << "4. Quit \n\n"; cin >> choice; if (choice >=1 && choice <=4){ //if choice between 1-4 cout << "Thanks for you choice" <<endl; } while(1) { switch (choice) //circle area { case CIRCLE_AREA1: cout << "enter any number" <<endl; cin >> radius; if (radius < 0 ) { cout << "You must enter a positive number" <<endl; } else { AREA = radius * radius * pi; cout << "The radius of the circle is " << AREA <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } } //rectangle area switch (choice) { case Rectangle_AREA2: cout << " Put a length of a rectangle " <<endl; cin >> length; if ( length < 0 ) { cout <<"You must enter a postive number " <<endl; break; } else { cout << "Enter a width of a rectangle" <<endl; cin >> width; area = length * width; cout << "The area of the rectangle is " << area <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } } switch (choice) { case TRIANGLE_AREA3: cout << " enter any number " <<endl; cin >> base; if ( base < 0 ) { cout <<"You must enter a postive number " <<endl; break; } else { cout << "Enter a height of a triangle base" <<endl; cin >> height2; area2 = base * height2 * 0.5; cout << "The area of the triangle is " << area <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } //quit choice switch (choice) { case QUIT_WAY2:{ return 0; }}}}}
#16
Posted 23 September 2012 - 01:37 PM
#include <iostream> #include <iomanip> #include <stdlib.h> #include <cstdlib> using namespace std; int main() { // contains the variables // variables double AREA; double circle; double Triangle; int Quit; int choice; double pi; //radius pi = 3.14159; double radius; /// rectangle double Rectangle; double area; double number; double length; double width; //triangle double TRIANGLE; double AREA3; double base; double height2; double area2; // quit double WAY2; double answer; char input; char n; //asks the user which one and displays it //constants for menu choices const int CIRCLE_AREA1 = 1, Rectangle_AREA2 = 2, TRIANGLE_AREA3 = 3, QUIT_WAY2 = 4; // display the choices cout << "1. Calculate the Area of a Circle\n\n" << "2. Calculate the area of a Rectangle \n\n" << "3. Calculate the Area of a Triangle \n\n" << "4. Quit \n\n"; cin >> choice; if (choice >=1 && choice <=4){ //if choice between 1-4 cout << "Thanks for you choice" <<endl; } while(1) { switch (choice) //circle area { case CIRCLE_AREA1:{ cout << "enter any number" <<endl; cin >> radius; if (radius < 0 ) { cout << "You must enter a positive number" <<endl; } else { AREA = radius * radius * pi; cout << "The radius of the circle is " << AREA <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } } //rectangle area case Rectangle_AREA2:{ cout << " Put a length of a rectangle " <<endl; cin >> length; if ( length < 0 ) { cout <<"You must enter a postive number " <<endl; break; } else { cout << "Enter a width of a rectangle" <<endl; cin >> width; area = length * width; cout << "The area of the rectangle is " << area <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } } case TRIANGLE_AREA3:{ cout << " enter any number " <<endl; cin >> base; if ( base < 0 ) { cout <<"You must enter a postive number " <<endl; break; } else { cout << "Enter a height of a triangle base" <<endl; cin >> height2; area2 = base * height2 * 0.5; cout << "The area of the triangle is " << area <<endl; cout << "Enter a number 1-4 to continue" <<endl; cin >> choice; break; } //quit choice case QUIT_WAY2:{ return 0; }}}}}
Now it works. You should google for switch/case statements in c++, you can't use switch after every case, you use switch only ones. For example, if you want check if number is equal 5:
switch(number){
case 1:
cout << "NUmber is not 5";
case 2: ...
case 3: ...
case 4: ...
case 5:
cout << "Number is 5".
I hope you understand
#17
Posted 23 September 2012 - 01:43 PM
That was the problem. I get it. I was using switch after every statement. I get it now. Thanks so much for all your help.
Also tagged with one or more of these keywords: c++, loop
Language Forums →
C and C++ →
Do you use any debuggers except the standard for Visual Studio?Started by Fernando, 25 Jan 2019 ![]() |
|
![]() |
||
Tutorial Forums →
C/C++ Tutorials →
Basic C++ Game Hacking TutorialStarted by DaDopeman, 12 Aug 2018 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
basic c++ question, difference between a and a&Started by Siten0308, 10 Oct 2017 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
help me . c++. ArraysStarted by girl2383, 06 Feb 2017 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Trying to makes sense of unnamed namespace and extern useStarted by sonar87, 25 Jan 2017 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download