You all rock! I think I have it now. I can see what the lines are doing at each call!!
I have used my debugger a bit, and it helps too, but not like this!!!
Thank so much!
Cougarclaws
You all rock! I think I have it now. I can see what the lines are doing at each call!!
I have used my debugger a bit, and it helps too, but not like this!!!
Thank so much!
Cougarclaws
Thank you very much! I do see that.
I guess what I am interested in is how the machine sees this to slove it. Is there a way to look at each call and understand it? It has been explained to me to be like a tree, first down, then back up. I have a few examples, but I am unclear.
Also, I am having trouble picturing the events that occur in the line after the else statement, no matter the value. I want to understand what is happening here when this executes. I created this to give me the answers, but it did not help me understand the recursive process itself.
I know I am asking much here, so I want to thank everyone in advance who responds....I may not have the mind for this, just want to try.
Thanks,
Cougarclaws
Is there an easier way to understand what this is doing step by step? I get very confused here, and I wonder if any of you fine people have a trick for breaking this down. I really want to get this, and understand the pattern, but what happens in the "else" return confuses me.
Thanks,
Cougarclaws
#include <iostream>
using namespace std;
float wk7recur (float value, int num)
{
if (num == 0)
return 1;
else
return ( value * wk7recur (value, num - 1) );
}
int main()
{
float answer = wk7recur (1.0, 5);
cout << answer;
cout << endl << endl;
system ("PAUSE");
return 0;
}
First, thank you again for all your time and hard work.
I think I have this now.
Only 3 more weeks to go, then on to the next class! I am so happy for these forums and people like yourself who are willing to help out.
Cougarclaws
I am still confused, but I see where you are going. I will plat with it some to see how I can incorporate it.
Thanks!
OK, with some help from all of you, I have this working, but I am at a loss as to how to display the number of steps the user asks to show (if they say 10, then every tenth answer displays until the final one) and we need this to display 9 decimal places which I can do with setprecision I think. Then I will have a final answer to display once all is said and done. How in the world would I even begin to get it to display this?
You all rock!
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//function to read inputs from the user test for proper input
//and return the value to main if input is invalid,
//the user will be reprompted for proper input
int validInput (string prompt)
{
int userIn1 = 0;
cin >> userIn1; cout << endl;
while (userIn1 < 1)
{
cout << "Error, cannot be 0 or negative, please try again" << endl;
cin >> userIn1; cout << endl;
}
return userIn1;
}
int main()
{
double pi = 0;
int numCalc = 0;
int userIn1 = 0;
int times = 0;
string userInput = "Please enter the number of terms to use: ";
string userDisplay = "Please enter how often to display steps: ";
cout << "This program calculates the value of PI to varying degrees of accuracy " << endl;
cout << endl;
cout << "The accuracy is based on the desired number of …
I think I got it!
Thank you soooo, much again!
Cougarclaws
OK, I changed it and I think I can make it work, but it won't compile.
"too many arguments to function int valid input [std::string]
Can you see what I an doing wrong?
Thanks again!
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//function to read inputs from the user test for proper input
//and return the value to main if input is invalid,
//the user will be reprompted for proper input
int validInput (string prompt)
{
int userIn1 = 0;
cin >> userIn1; cout << endl;
while (userIn1 < 1)
{
cout << "Error, cannot be 0 or negative, please try again" << endl;
cin >> userIn1; cout << endl;
}
return userIn1;
}
int main()
{
double pi = 0;
int numCalc = 0;
int userIn1 = 0;
int times = 0;
string userInput = "Please enter the number of terms to use: ";
string userDisplay = "Please enter how often to display results: ";
cout << "This program calculates the value of PI to varying degrees of accuracy " << endl;
cout << endl;
cout << "The accuracy is based on the desired number of calculations requested by user" << endl;
cout << "The user may also decide the sequence of displayed output during calculations" << endl;
cout << endl << endl;
cout << userInput << endl;
numCalc = validInput (userInput, "Prompt");
cout << userDisplay << endl;
times = validInput (userDisplay, "Prompt");
// Calculating pi/4
for (double n = 1; n <= …
Hi again,
My logic is not too good. I am supposed to get this function to be used twice for two different inputs calling the "strings" from within the function and returning the values to main (perhaps my mistake is attempting to call this program twice??? except that is what the instructor has asked for). I can get that to work, but I am trying to get it so it returns the values input when asked for the correct string. I am having trouble finding a loop that I can use to get it to ask for terms the first time through, then the display otions the second time.... I am VERY good at looping my machine forever, but no luck geting the alternate questions and answers to work.
suggestions?
Thanks,
Cougarclaws.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//function to read inputs from the user test for proper input
//and return the value to main if input is invalid,
//the user will be reprompted for proper input
int validInput ( )
{
int userIn1 = 0;
int userIn2 = 0;
int count = 0;
int displayCount = 0;
string userInput = "Please enter the number of terms to use: ";
string userDisplay = "Please enter how often to display results: ";
for (int count = 0; count == 0; count++)
if (count == 0)
cout << userInput;
cout << userDisplay;
cin >> userIn1; cout << endl;
while ( userIn1 < 1)
{ …
I think you fixed it. I was looking at the starting parameters and not the return to main. Yours compiles just as it should.
You are awesome. I think I now have a formula for Pi as well.
Thank you for all the time you spent with me. I hope one day to do the same for others. My reputation here took a hit on a very frustrating day, and I was just trying to point out that I wasn't getting any suggestions to fix my issues, just that they were bad.
I am a Network Engineer trying to learn this, so I am way out of my comfort zone and feel a bit intimidated.
You have been great!!!
Thanks again!
Cougarclaws.
I guess I don't understand why my string does not print to the screen and the user get challenged for the input.
Cougrclaws
Thank you again! The program will not compile if I use () in the function. If I do not declare userIn1 in main, then I get "too many arguments". I am very confused. My instruction for this are :
Write a user defined function to read input from the user. The requirements for the function are:
The prompt for user input will be stored in a STRING type variable and passed as an input argument to the function.
The function will prompt the user for input and then use a loop to verify that the user input is positive and non 0. If not, the fuction returns an error and request for the input again.
Once valid input is entered, the value gets passed back to main.
So, am I that far off??
Thanks,
Cougarclaws
This is what it looks like now.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//function to read inputs from the user test for proper input
//and return the value to main if input is invalid,
//the user will be repormpted for proper input
int validInput (int userIn1)
{
int displayCount = 0;
string userInput = "Please enter the number of terms to use: ";
cout << userInput;
cin >> userIn1; cout << endl;
while ( userIn1 < 1)
{
cout << "Error, cannot be 0 or negative" << endl;
cout << userInput;
cin >> userIn1; cout << endl;
}
return userIn1;
}
int main()
{
int numCalc = 0;
int userIn1 = 0;
cout << "This program calculates the value of PI to varying degrees of accuracy " << endl;
cout << endl;
cout << "The accuracy is based on the desired number of calculations requested by user" << endl;
cout << "The user may also decide the sequence of displayed output during calculations" << endl;
cout << endl << endl;
numCalc = validInput (userIn1);
cout << endl << endl;
system ("PAUSE");
return 0;
}
You rock, in delcaring the variable "userIn1" in my main, The program now will run ( I did this before) , but I still get no output for the user input from the function. My "userInput string" does not show up.
Any ideas?
And thank you very much,
Cougarclaws
Hi all,
I have tried this several ways. I need to get the user function to return userIn1 to main. I don't need to read anything from the call to the function, but if I leave out paraneters, it really does not work. My original issue was that the string value and print outputs are not showing up. I believe this is because of my inability to fix the function. I will have to use the function for this assignment twice, so if there is more I need to do to get that to work (once built for displayCount), please guide me. Thanks for all the help in advance!
I have not even started the PI accuracy side of this yet, so since I know this is a common HW assignment, any help with understanding how the formula would get written is appreciated as well.
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
//function to read inputs from the user test for proper input
//and return the value to main if input is invalid,
//the user will be repormpted for proper input
int validInput (int)
{
string userInput = "Please enter the number of terms to use: ";
int userIn1 = 0;
int displayCount = 0;
cout << userInput;
cin >> userIn1; cout << endl;
while ( userIn1 < 1)
{
cout << "Error, cannot be 0 or negative" << endl;
cout << userInput;
cin >> userIn1; cout << endl;
}
return userIn1;
}
int main() …
You are all incredible! Thank you soo much for the help! I see my errors. I just want to improve, and this really helps
Thank you
Thanks for all the help, I really appreciate it. If you ever need help on routing or administration, I'd be happy to help you. So far, you have pointed out issues and offered no real suggestions. At least I am doing my best to try and get this. Usually the people here are much kinder. This was a mistake. I wll go away since it is obvious nothing I am doing is acceptable and your tiltle here is "team colleage" At this point I will find another forum or perhaps a friend for some real help.
Thanks again!
Is this right?
#include <iostream>//I/O
#include <iomanip>//output manipulation library
using namespace std;
const double MALE_AGE_14_16 = .095;
const double FEMALE_AGE_14_16 = .080;
const double MALE_AGE_17_21 = .082;
const double FEMALE_AGE_17_21 = .069;
const double MALE_AGE_22_26 = .074;
const double FEMALE_AGE_22_26 = .058;
const double MALE_AGE_27_30 = .062;
const double FEMALE_AGE_27_30 = .052;
const double ALL_AGES_31_64 = .051;
const double ALL_AGES_65_75 = .062;
const double ALL_AGES_75_OVER = .075;
//function determines current insurance rates based on age and gender
double chart (int currentAge, char gender)
{
double rate = 0;
if (gender == 'M' || 'm')
if (currentAge < 16)
rate = MALE_AGE_14_16;
else if ((currentAge > 17) && (currentAge <= 21))
rate = MALE_AGE_17_21;
else if ((currentAge > 22) && (currentAge <= 26))
rate = MALE_AGE_22_26;
else if ((currentAge > 27) && (currentAge <= 30))
rate = MALE_AGE_27_30;
else if (gender == 'F' || 'f')
if (currentAge < 16)
rate = FEMALE_AGE_14_16;
else if ((currentAge > 17) && (currentAge <= 21))
rate = FEMALE_AGE_17_21;
else if ((currentAge > 22) && (currentAge <= 26))
rate = FEMALE_AGE_22_26;
else if ((currentAge > 27) && (currentAge <= 30))
rate = FEMALE_AGE_27_30;
if (gender == 'O')
if ((currentAge >= 31) && (currentAge <= 64))
rate = ALL_AGES_31_64;
else if ((currentAge > 65) && (currentAge <= 75))
rate = ALL_AGES_65_75;
else if (currentAge > 75)
rate = ALL_AGES_75_OVER;
//test
cout << rate;
return rate;
}
//Inquires for user input and disqualifies underage drivers with a warning and exit
int main ()
{
int currentAge = …
Ok then, I read them and missed something. "read the threads again" offers little help. Perhaps a link to the proper thread?
I want to do this right, but I am obviously new to programming, so anything you can tell me would be great. I did a search and found some explanations, but there was no "step by step".
This is what I read "To use it, Simply encase your code in:
and
tags".
Thanks,
OK, I hope I "wrapped it correctly, but if not, please advise and I will be sure to do this correctly from here.
I am having issues getting my nesting to work. Can I go this deep? Should I try switches? The program function should return values based on age and gender to "rate".
Thanks in advance!
cougarclaws.
#include <iostream>//I/O
#include <iomanip>//output manipulation library
using namespace std;
const double MALE_AGE_14_16 = .095;
const double FEMALE_AGE_14_16 = .080;
const double MALE_AGE_17_21 = .082;
const double FEMALE_AGE_17_21 = .069;
const double MALE_AGE_22_26 = .074;
const double FEMALE_AGE_22_26 = .058;
const double MALE_AGE_27_30 = .062;
const double FEMALE_AGE_27_30 = .052;
const double ALL_AGES_31_64 = .051;
const double ALL_AGES_65_75 = .062;
const double ALL_AGES_75_OVER = .075;
//function determines current insurance rates based on age and gender
double chart (int currentAge, char gender)
{
double rate = 0;
if (gender == 'M' || 'm')
if (currentAge < 16)
rate = MALE_AGE_14_16;
else if ((currentAge > 17) && (currentAge <= 21))
rate = MALE_AGE_17_21;
else if ((currentAge > 22) && (currentAge <= 26))
rate = MALE_AGE_22_26;
else if ((currentAge > 27) && (currentAge <= 30))
rate = MALE_AGE_27_30;
else if (gender == 'F' || 'f')
if (currentAge < 16)
rate = FEMALE_AGE_14_16;
else if ((currentAge > 17) && (currentAge <= 21))
rate = FEMALE_AGE_17_21;
else if ((currentAge > 22) && (currentAge <= 26))
rate = FEMALE_AGE_22_26;
else if ((currentAge > 27) && (currentAge <= 30))
rate = FEMALE_AGE_27_30;
if (gender == 'O')
if ((currentAge …
Thank you this makes sense. It works well.
Cougarclaws
I think it should be:
// calcTotStat += .5; roundCalc = (int) (calcTotStat / 1000); if ((int) calcTotStat % 1000 > 0) roundCalc++; roundCalc *= 1000;
Thanks, I couldn't get this to return a value either.
I think my parameters are correct, but it just isn't working for me.
Cougraclaws
Hi All,
I Think I am close. I am trying to write a small user function that gives "roundCalc" to the main as a rounded number UP to the nearest 1000. (If 1011 should round up to 2000). I have "calcTotStat" reading in, and I thought I had it right, but my cout statement is returning 0.00. I know this is simple for all the experts, but after 10 hours yesterday on program 1 for class, and 3.5 hours today, I think my brain is fried.lol.
Thanks in advance,
#include <iostream>//I/o
#include <iomanip>//output manipulation library
#include <cctype>//function for character manipulation
#include <string>//string library
using namespace std;
//This finstion will round value from calculated line 6
//and will return a number rounded to nearest multiple of 1000
double round(double calcTotStat)// parameters for function
{
double roundCalc;
calcTotStat += .5;
roundCalc = (int) (calcTotStat / 1000);
roundCalc * 1000;
return (roundCalc); // return to main
}
//body of program will get user inputs for processing and calculations
//output text to user for inqueries
int main()
{
const double CHILD_ALLOWANCE = 1000;
const int SINGLE = 75000;
const int MARRIED_JOINT = 110000;
const int HEAD_HOUSE = 75000;
const int QUALIFY_WID = 75000;
const int MARRIED_SEP = 55000;
int children, fileStatus;
double childTaxPrevious, childAllow, remainCredit, grossAdjust, calcTotStat;
double roundCalc;
cout << "Enter the number of qualifying children: "; cin >> children; cout << endl;//ask for user input for children variable
cout << endl;
//calculate for line 1
childAllow = children * …
Thank you so much! I see I am bracket challenged!!!
Hi all,
Class assignment is to list all numbers between user input.
I have this much, but have no idea how to get it to list the numbers between them. I know this is simple, but it still eludes me ;)
Thanks in advance!
#include <iostream>
using namespace std;
int main ()
{
int x, y;
cout << "Please key in a start number: "; cout <<endl;
cin >> x;
cout << endl;
cout << "Please key in an end number: "; cout << endl;
cin >> y;
while (x < y)
x = x + 1;
cout << x;
cout << endl << endl;
system ("PAUSE");
return 0;
}