crash - Beginner programmer; program instantly closes on switch (C++) -


I am walking around with your very basic C ++ knowledge of programming (for two days) I am trying to write a program that calculates the user input around the PHI (1.61803399).

Here's the code, if it's a mess:

  #include  using namespace std; // prototype: flat fyxpo; Flat Fig NXPO; Float opt1f (float phi, float userInput) {return userInput * phi;} float opt2f (float then, float User Input) {userUnput / phi}; float opt3f () {return phiExpo;} float opt4f () {return phiNegExpo;} Float phiExpof (float phi, float userInput) {pow (phi, userInput);} float PhiNegExpof (float then, float User Input) {Paw (FEI , -usernameinput);} / exact program: int main () {float user input; Int userChoice; Float fee = 1.61803399; Float Fiexpo; Flat Fig NXPO; Cout & lt; & Lt; "I want (press this number, then log in):" & lt; & Lt; Endl; The court's & lt; & Lt; Endl; Beginners: cout & lt; & Lt; "1. Multiplied by PHI:" & lt; & Lt; Endl; Cout & lt; & Lt; "2. Divide by:" & lt; & Lt; Endl; Cout & lt; & Lt; 3. Exponent Fi: & lt; & Lt; Endl; Cout & lt; & Lt; "4. Negative exponent fe:" & lt; & Lt; Endl; The court's & lt; & Lt; Endl; CIN & gt; & Gt; User options; The court's & lt; & Lt; Endl; Switch (User Choice) {Case 1: Cott & lt; & Lt; Enter the number for "multiplication:"; CIN & gt; & Gt; UserInput; Return opt1f (file, user input); Case 2: Cotton and LT; & Lt; Enter the number for "Division:"; CIN & gt; & Gt; UserInput; Return opt2f (file, user input); Case 3: Cot and LT; & Lt; "Enter the number for xonietate by phi:"; CIN & gt; & Gt; UserInput; Return opt3f (); Case 4: Cot and LT; & Lt; "Enter the numbers for exponentietie negatively:"; CIN & gt; & Gt; UserInput; Return opt4f (); Default: cout & lt; & Lt; "Please enter a number from 1 to 4."; The court's & lt; & Lt; Endl; The court's & lt; & Lt; Endl; Goto beginners; } Cin.get (); }   

However, when you enter a number on the first signal (1-4), program crashes only on the desktop, and why can not convince me.

Your program does not stop at the switch statement when I drive; I though I would get to the second text some problems that I get:

First, the faster ones attention, equally return turned out the application instead of the response output .

Secondly, code to cure instead of return, you want to put in "break"; So you do not run the code in any condition after the current situation.

Third, you might want to add the option to turn Goto into an input loop and leave it in your menu. It's more of a stylish choice, but I think you'll find that it's difficult to debug in Goto's C / C ++ in the future.

-Edit: For formatting- OK, thinking that you want to be able to do more than one task in running the program, and to get rid of Goto, you can do something like this. :

  Skip boolean = false; Do {cout & lt; & Lt; "1) Menu item 1" & lt; & Lt; Andal & lt; & Lt; "2) Quit" & lt; & Lt; Endl; Cin.get (user options); Switch (userchoice) {case 1: cot and lt; & Lt; "Please enter the input for option 1:"; Cin & gt; & Gt; user input; Cout & lt; & Lt; Case1function (userInput); break; Case 2: Skip = True; break; Default: cout & lt; & Lt; "Please read the menu" & lt; & Lt; Endl; }} While (leaving!);    

Comments