Scenario: I am trying to create a recursion function that takes a number from the user. That number then goes through to equations where it squares the number and takes the square root of it. Then, that value is supposed to be sent back through the function, through the same equations. Then, I am trying to output the value of each iteration. The amount of iterations is a random number. This code is in C++ and I am using Visual Studio 2023. I have attached the code I, myself, typed and picture of the output. Also, this is a header file that is being called from my source.cpp file (case 5 in switch case). That is why I am entering 5 as the first input when I run the program. Problem: The output only shows one iteration of calculation, then goes straight back into taking an input from the user. What am I doing wrong?

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter7: File Handling And Applications
Section: Chapter Questions
Problem 7PE
icon
Related questions
Question

Scenario:

I am trying to create a recursion function that takes a number from the user. That number then goes through to equations where it squares the number and takes the square root of it. Then, that value is supposed to be sent back through the function, through the same equations. Then, I am trying to output the value of each iteration. The amount of iterations is a random number.

This code is in C++ and I am using Visual Studio 2023. I have attached the code I, myself, typed and picture of the output. Also, this is a header file that is being called from my source.cpp file (case 5 in switch case). That is why I am entering 5 as the first input when I run the program.

Problem:

The output only shows one iteration of calculation, then goes straight back into taking an input from the user. What am I doing wrong?

100 %
File
Source.cpp
++ Assignment 4
{
HARACTORENMERGE%2525
1
3
4
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
26
27
28
29
30
31
32
33
34
35
36
37
38
Edit View Git Project Build Debug Test Analyze
Ready
L
#pragma once
using namespace std;
RecursionFunction.h X TwoRandomCalculations.h
int loopNum;
int userNum;
double numPower;
double numSqrt;
{
Bint recursionFunction()
cin >> userNum;
// Loop Randomization:
srand((unsigned)time(NULL));
loopNum = rand() % 10 + 1;
Debug
if (loopNum > 0)
{
else
x64
// User input of number to be calculated through two equations:
cout << "Enter a number to calculate: ";
numPower = pow(userNum, 2);
numSqrt = sqrt(userNum);
return 0;
cout << "\n" << numPower << endl;
cout << numSqrt << endl;
loopNum = loopNum - 1;
return recursionFunction();
✔ No issues found
Tools Extensions Window
cout << "We will loop through both calculations " << loopNum <<
Local Windows Debugger ▾ ▷
FlipCoin.h
Countdown.h
(Global Scope)
Help
" times.
11
Auto
Search ▾
Assignment 4
RandomCalculation.h
<< endl;
abc
GradeCalculator.h
云
recursion Fun
Transcribed Image Text:100 % File Source.cpp ++ Assignment 4 { HARACTORENMERGE%2525 1 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 23 24 26 27 28 29 30 31 32 33 34 35 36 37 38 Edit View Git Project Build Debug Test Analyze Ready L #pragma once using namespace std; RecursionFunction.h X TwoRandomCalculations.h int loopNum; int userNum; double numPower; double numSqrt; { Bint recursionFunction() cin >> userNum; // Loop Randomization: srand((unsigned)time(NULL)); loopNum = rand() % 10 + 1; Debug if (loopNum > 0) { else x64 // User input of number to be calculated through two equations: cout << "Enter a number to calculate: "; numPower = pow(userNum, 2); numSqrt = sqrt(userNum); return 0; cout << "\n" << numPower << endl; cout << numSqrt << endl; loopNum = loopNum - 1; return recursionFunction(); ✔ No issues found Tools Extensions Window cout << "We will loop through both calculations " << loopNum << Local Windows Debugger ▾ ▷ FlipCoin.h Countdown.h (Global Scope) Help " times. 11 Auto Search ▾ Assignment 4 RandomCalculation.h << endl; abc GradeCalculator.h 云 recursion Fun
File
100 %
Source.cpp
++ Assignment 4
1
2
3
4
5
678910mp3uwspaa233
11
14
15
22
24
Edit View
*
25
26
27
28
29
30
31
32
33
34
35
36
37
20
==========
|-|
Build failed
Git Project Build Debug Test Analyze
5
RecursionFunction.hX TwoRandomCalculations.h
double numEnter a number to calculate: 3
double numCalculations for loop 2:9
1.73205
Bint recurs Enter a number to calculate:
{
// Use
cout <
cin >>
// Loo
srand(
LoopNu
cout <
#pragma once
using namespace std;
int loopNu C:\Users\SR Cuestas\Desktop\ECE 1310\Assignment 4\Assignment 4\x64\Debug\Assignment 4.exe
int userNuEnter a number between 0 and 6 (Including 0 or 6): 5
if (lo
{
nu
nu
Debug
со
со
lo
else
x64
re
return 0;
No issues found
Tools Extensions Window Help
Local Windows Debugger
FlipCoin.h
Output
Show output from: Build
Build started...
1>------ Build started: Project: Assignment 4, Configuration: Debug x64
Countdown.h
(Global Scope)
==========
O Search
Auto
Assignment 4
RandomCalculation.h
abc
GradeCalculator.h
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(1134,5): error MSB6006: "link.exe" exited with code 1168.
1>LINK : fatal error LNK1168: cannot open C:\Users\SR Cuestas\Desktop\ECE 1310\Assignment 4\Assignment 4\x64\Debug\Assignment 4.exe for writing
1>Done building project "Assignment 4.vcxproj" FAILED.
Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
========== Build started at 19:01 and took 01.048 seconds == ======
谓凄喔见习习习
=
recursion Function()
↑ Add t
Transcribed Image Text:File 100 % Source.cpp ++ Assignment 4 1 2 3 4 5 678910mp3uwspaa233 11 14 15 22 24 Edit View * 25 26 27 28 29 30 31 32 33 34 35 36 37 20 ========== |-| Build failed Git Project Build Debug Test Analyze 5 RecursionFunction.hX TwoRandomCalculations.h double numEnter a number to calculate: 3 double numCalculations for loop 2:9 1.73205 Bint recurs Enter a number to calculate: { // Use cout < cin >> // Loo srand( LoopNu cout < #pragma once using namespace std; int loopNu C:\Users\SR Cuestas\Desktop\ECE 1310\Assignment 4\Assignment 4\x64\Debug\Assignment 4.exe int userNuEnter a number between 0 and 6 (Including 0 or 6): 5 if (lo { nu nu Debug со со lo else x64 re return 0; No issues found Tools Extensions Window Help Local Windows Debugger FlipCoin.h Output Show output from: Build Build started... 1>------ Build started: Project: Assignment 4, Configuration: Debug x64 Countdown.h (Global Scope) ========== O Search Auto Assignment 4 RandomCalculation.h abc GradeCalculator.h 1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(1134,5): error MSB6006: "link.exe" exited with code 1168. 1>LINK : fatal error LNK1168: cannot open C:\Users\SR Cuestas\Desktop\ECE 1310\Assignment 4\Assignment 4\x64\Debug\Assignment 4.exe for writing 1>Done building project "Assignment 4.vcxproj" FAILED. Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== Build started at 19:01 and took 01.048 seconds == ====== 谓凄喔见习习习 = recursion Function() ↑ Add t
Expert Solution
steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
Systems Architecture
Systems Architecture
Computer Science
ISBN:
9781305080195
Author:
Stephen D. Burd
Publisher:
Cengage Learning