Question

for c++ switch structure, how do i input where the user can enter an angle in...

for c++ switch structure, how do i input where the user can enter an angle in either degrees or radians. For example 30 d or 30 D or 1.5 r or 1.5 R? Is there a simple way of inputting this in a switch case?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

#include <string>

using namespace std;

int main() {

typedef enum {

radian =0, // is 0

degree =1 // is 1

  

} angle;

int choice; // 0, 1, 2

cout << "choice either 0 or 1 0 for radian 1 for degree: ";

cin >> choice;

double angleValue;

cout<<"value of angle ";

cin>> angleValue;

switch (choice)

{

case degree:

cout << angleValue << " D";

break;

case radian:

cout << angleValue << " R";

break;

// ...

}

return 0;

}

you have to use enum as c++ doesnot support string in switch statement

angle; 12 13 int choice; // e, 1, 2 14 15 cout << choice either 0 or 1 e for radian 1 for degree: 16 cin > choice; 17 doub

Add a comment
Know the answer?
Add Answer to:
for c++ switch structure, how do i input where the user can enter an angle in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program to analyze a variety of triangles. The program should determine all angles...

    Write a C++ program to analyze a variety of triangles. The program should determine all angles and all sides for a triangle for three different options (give the user a menu of choices): 1) Given two sides and the angle between 2) Given two angles and one side 3) Given three sides More details for each option is provided below. Option 1: Given two sides and the angle between First check to be sure that the three values entered are...

  • in Mips how do i get a input string from a user and then print it...

    in Mips how do i get a input string from a user and then print it to the screen? for example if a user enters A6B4GYJx how do i get that and then print it to the screen?

  • JAVA I need a switch so that users can input one selection then another. These selections...

    JAVA I need a switch so that users can input one selection then another. These selections are for a simple calculator that uses random numbers 1. + 2. - 3. * 4./ 5. RNG. This has to be simple this is a beginners class. Here is what I have import java.util.Scanner; import java.util.Random; import java.util.*; public class You_Michael02Basic_Calculator {    public static void main(String[] args) {        // Generate random numbers        int num1,num2;        num1 =(int)(Math.random()*100+1);...

  • 1) [5 pts] Build a simple calculator using switch statements which can perform the four operations...

    1) [5 pts] Build a simple calculator using switch statements which can perform the four operations +, -, *,/. Write a program that asks the user to enter two numbers/operands. Then prompt the user to enter the operator +,, ). Perform the corresponding operation and display the answer to user. The format Example of multiplication Microsoft Visual Studio Debug Console an operator (+, -, *, ): Enter two operands: 25.5 2.314 25.5 2.314597 2) [5 pts] Create a program to...

  • Write a C code using switch statement that will ask the user to enter a character....

    Write a C code using switch statement that will ask the user to enter a character. This character should be one of the first three characters of your name. The code then should check for the value of the character and output the following: If the character is the same as yo&r first letter then output "X=10" If the character is the same as your second letter then output "Y=5" If the character is the same as your Third letter...

  • Do it on C++ please Do it on C++ please .Question 2: Take a user input...

    Do it on C++ please Do it on C++ please .Question 2: Take a user input integer, and print out the digit by digit. (can enter any positive number, e.g. 123, 34567,37.. (hint: first you need to find the digit of integer, use while loop to find the digit of integer, then look the exercise 6 of lecture 5) Example: . Enter an integer: 123456789 e first digit: 1 o second digit: 2 o ninth digit: 9

  • C++ only Implement a program that prompts a user to enter a number N where N...

    C++ only Implement a program that prompts a user to enter a number N where N is a positive number. The program must validate a user input and ask a user to re-enter until an input is valid. Implement a function that pass N as an argument and return a result of calculates N! (N-factorial): The function must use loop for the implementation. Hint: Factorial: N! = N * (N-1) * (N-2) * …. * 1 ( This is only...

  • Use a switch statement to build a menu-driven calculator

    ENGR 40 PROGRAMMING ASSIGNMENT MENU-DRIVEN CALCULATOR PROGRAM Use a switch statement to build a menu-driven calculator. Your program should ask the user to choose from a list of ten possible functions (square root, square, natural log, common log, e'x yx, 1/x, sin(x), cos(x), and tan(x). Each choice will correspond to an integer -example: (1) square root, (2) square, etec. Once the person has input a function choice then a switch statement will control the flow of the program- ie. the program...

  • C Program: How do I create two linked lists of characters from user input and concatenate...

    C Program: How do I create two linked lists of characters from user input and concatenate the two linked lists?

  • Hello, I have a assignment where the user inputs a word and the out will then...

    Hello, I have a assignment where the user inputs a word and the out will then tell the user how many of the five vowels are in the word so for example if I typed the word hello, it would output {0 1 0 0 0 } since there is only one vowel and that is e which is in the second row, I have most of it done, but I can't seem to figure out how to get the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT