I have tried tirelessly to get this right, but nothing seems to work. A lot of what I do brings me to an error 'Control may reach end of non-void function'.
Basically, we created a program to output gas usage statistics. What I am stuck on is:
"Gas will rise in price from the defined initial value to the defined final value over the course of 4 years, then remain fixed at that higher value for the next 4 years."
I feel like there should be a loop or function for this, but every time I make NUM_YEARS an int rather than a const, no matter what the program tells me 'Control may reach end of non-void function.'
Below is the program:
#include <cstdlib>
#include <iostream>
using namespace std;
const int MILES_PER_YEAR = 21000;
const double CITY_PERCENT = 45.0;
const double HIGHWAY_PERCENT = 55.0;
const double CITY_MPG = 51.0;
const double HIGHWAY_MPG = 45.0;
const double USABLE_GAS = 9.0;
const double INITIAL_PRICE = 3.359;
const double FINAL_PRICE = 6.00;
const int NUM_YEARS = 8; //This will be the total number of years
double gasPrice(int day);
int main(int argc, char * argv[]) {
cout << "Driving the Toyota Prius" << endl;
double daily_miles = MILES_PER_YEAR / 365.0;
double daily_city_miles = daily_miles * CITY_PERCENT/100.0;
double daily_highway_miles = daily_miles*HIGHWAY_PERCENT/100.0;
double daily_gas_consumed = daily_highway_miles / HIGHWAY_MPG +
daily_city_miles / CITY_MPG;
double gas_in_tank = USABLE_GAS;
double price;
double amount_purchased;
double gallons_purchased;
double total_gas_purchases = 0;
for(int day = 0;day < 365*8; day++) { //If the day is less than the total number of days in 8 years, add one day
cout << "Driving summary for day " << day << endl;
cout << " highway miles: " << daily_highway_miles << endl;
cout << " city miles : " << daily_city_miles << endl;
cout << " gas consumed : " << daily_gas_consumed << endl;
gas_in_tank = gas_in_tank - daily_gas_consumed;
cout << " gas in tank : " << gas_in_tank << endl;
if (gas_in_tank < 0.0) {
cout << " BUY GAS" << endl;
gallons_purchased = USABLE_GAS - gas_in_tank;
price = gasPrice(day);
cout << " price today is : " << price << endl;
cout << " Gallons purchased: " << gallons_purchased << endl;
cout << " fillup cost : " << gallons_purchased * price << endl;
total_gas_purchases = total_gas_purchases + gallons_purchased * price;
cout << " total gas cost : " << total_gas_purchases << endl;
gas_in_tank = USABLE_GAS;
}
}
system("PAUSE");
return EXIT_SUCCESS;
}
double gasPrice(int day, int YEAR_NUM) {
if (int day=365) { //call YEAR_NUM, for day=365, increase YEAR_NUM by 1
YEAR_NUM++;
day = 0;
}
if (YEAR_NUM >= 4) {
double currentPrice = FINAL_PRICE;
currentPrice;
}
if (YEAR_NUM < 4) { //conditional price for the first four years
double dailyIncrease = (FINAL_PRICE - INITIAL_PRICE) / (NUM_YEARS * 365);
double currentPrice = (INITIAL_PRICE + day * dailyIncrease);
return currentPrice;
}
}
You need to return something in gasPrice that is outside of the for loop. The compiler is saying there is a chance that neither of the while conditions will be met, in which case there is no value to return.
On another note, the while loops do not make a lot of sense the way they are written. Just make them if statements.
I think if you move "return currentPrice;" out of those two while loops, it will fix the problem.
Function gasPrice has no return statement outside the for loop. As the function has a return type that is not void then if the return statement is absent the behaviour of the function will be undefined.
Related
Is something off with my formula for the variables especially for change_in_pennies or is the problem with my choices of the datatypes for the variables? When I input 270 or 280 I get almost everything correct except for the value of pennies where it's a completely random value or number where it should be zero
enter image description here
const double quarter_value {0.25};
const double dime_value {0.1};
const double nickle_value {0.05};
const double penny_value {0.01};
int main() {
int amount{}, change_in_dollars{}, change_in_quarters{},
change_in_dimes{}, change_in_nickles{};
double total{}, change_in_pennies{};
cout << "Enter an amount in cents : ";
cin >> amount;
cout << "You can provide change for this"
" change as follows: " << endl;
total = (static_cast <double> (amount) / 100);
cout << "total: " << total << endl;
change_in_dollars = (amount / 100);
cout << "dollars : " << change_in_dollars << endl;
change_in_quarters = (total - change_in_dollars) / quarter_value;
cout << "quarters : " << change_in_quarters << endl;
change_in_dimes = (total - change_in_dollars - (quarter_value * change_in_quarters)) / dime_value;
cout << "dimes : " << change_in_dimes << endl;
change_in_nickles = (total - change_in_dollars - (quarter_value * change_in_quarters) - (dime_value * change_in_dimes)) / nickle_value;
cout << "nickles : " << change_in_nickles << endl;
change_in_pennies = (total - (change_in_dollars) - (quarter_value * change_in_quarters) - (dime_value * change_in_dimes) - (nickle_value * change_in_nickles)) / penny_value;
cout << "pennies: " << change_in_pennies << endl;
return 0;
}
Like others have commented, the problem is likely that your double-to-int conversions are truncated rather than rounded, making even a tiny round-off error lead to a different result. To avoid this, use purely int arithmetic and work in units of cents. Or if you use doubles, make sure to apply std::round() before casting back to ints.
For this car wash simulation, your program reads in the car arrival time through an input file. The total wash time for a car is 3 minutes. Another car can not go into the wash while a car is being washed which will increase the waiting time. If a car departs at minute 3 the next car needs to go in at minute 4 if it has already arrived.
I have already tried reading in the file all at once and then creating another loop but that has not worked. I have tried many things, I think I am only having a problem with how to loop the program.
#include <iostream>
#include <cassert>
#include <fstream>
#include <queue>
#include <cstdlib>
using namespace std;
class averager {
private:
int cnt;
int sum;
public:
averager(){
cnt=0;
sum=0;
}
void plus_next_number(int value)
{
cnt++;
sum+=value;
}
double average_time()
{
assert(cnt>0);
return (sum/cnt);
}
int how_many_cars()
{
return cnt;
}
};
class Washmachine {
private:
int time_for_wash;
int time_left;
public:
Washmachine(int n) {
time_for_wash = n;
time_left = 0;
}
bool is_busy() {
return (time_left > 0);
}
void startWashing() {
if(!is_busy()) {
time_left = time_for_wash;
}
}
void one_second(){
if(is_busy()) {
--time_left;
}
}
};
int main() {
queue<int> waitQueue;
int carArrival;
averager cal;
ifstream infile;
ofstream arrivalrec;
arrivalrec.open("arrival_time.txt");
arrivalrec << "Car Number " << "Arrival Time " << "Car Wash Start Time " << "Departure Time "
<< "Wait Time "
<< "Total Time " << endl
<< endl;
int maxWaitTime; // maxWaitTime initially 0:00
int totalWaitTime; // total time customers wait
int endTime = 540; // times for the simulation
int totalServiceTime;
int startTime;
int carNum = 0; // number of cars washed in study
int washTime = 3; // fixed time for a wash in minutes
int DeptTime;
int TotalTime;
int timeleft=0;
int waitTime;
int temp;
int sw;
Washmachine carwashing(washTime);
infile.open("input.txt");
for (int startTime=0;startTime<=endTime;startTime++){
infile>>temp;
waitQueue.push(temp);
if((!carwashing.is_busy())&&(!waitQueue.empty())) {
carArrival=waitQueue.front();
waitQueue.pop();
waitTime=temp-carArrival;
cal.plus_next_number(temp-carArrival);
carwashing.startWashing();
}
carwashing.one_second();
if (maxWaitTime<waitTime)
maxWaitTime=waitTime;
// add waiting time for customer to totalWaitTime.
totalWaitTime+=waitTime;
totalServiceTime+=washTime;
startTime=temp+waitTime;
TotalTime=washTime+waitTime;
DeptTime=startTime +washTime;
// increment the number of customers served
carNum++;
// set washAvailable to false since equipment back in service
// output the summary data for the simulation include number of cars
// washed, average customer waiting time and pct of time wash operates
arrivalrec << carNum << " " << temp << " " <<startTime
<< " " << DeptTime << " " <<
waitTime << " " << TotalTime << endl
<< endl << endl;
}
arrivalrec << "Maximum customer waiting time for a car wash is "
<< "14 minutes" << endl;
arrivalrec << "Percentage of time car wash operates is 57 "
//<< ((totalServiceTime / endTime) * 100.0)
<< '%' << endl;
arrivalrec << "Number of customers remaining at " << endTime
<< " is 8"<<endl; //<< waitQueue.size() << endl;
arrivalrec<<"\nCars washed were: "<<carNum<<endl;
arrivalrec<<"\nThe average waiting time is: "<<cal.average_time()<<endl;
int car_denied=0;
while(!waitQueue.empty())
{
waitQueue.pop();
car_denied++;
}
arrivalrec<<"\nThe number of denied cars is: 2 "<<endl;
arrivalrec<<endl;
return 0;
}
Car Arrival 0 car start 0 car depart 3 wait time 0 total time 3
3 4 7 1 4
10 10 13 0 3
11 14 17 3 6
Please try the following loop for the main function of your Car washing simulation.
Instead of looping over startTime, the loop uses the simulation runTime. All events like putting a car to the queue, starting and documenting the car washing process as well as counting waitTime are done by conditions:
infile.open("input.txt");
infile >> temp;
carNum = 1;
for (runTime=1;runTime<=endTime;runTime++){
if (runTime == temp) {
waitQueue.push(temp);
infile >> temp;
}
if((!carwashing.is_busy())&&(!waitQueue.empty())) {
carArrival=waitQueue.front();
waitQueue.pop();
startTime = runTime;
waitTime=startTime-carArrival;
totalWaitTime = waitTime;
TotalTime = washTime + waitTime;
cal.plus_next_number(startTime-carArrival);
carwashing.startWashing();
}
else
{
waitTime++;
}
if (carwashing.is_busy())
carwashing.one_second();
if ((!carwashing.is_busy())&&(startTime >= DeptTime)) {
DeptTime = startTime + washTime;
totalServiceTime += washTime;
arrivalrec << carNum << " " << carArrival << " " << startTime
<< " " << DeptTime << " " <<
totalWaitTime << " " << TotalTime << endl
<< endl << endl;
carNum++;
}
}
Please note that the file reading of the first car is done outside of the loop.
I also added the runTime variable and some initialization to your declaration:
queue<int> waitQueue;
int carArrival = 0;
averager cal;
ifstream infile;
ofstream arrivalrec;
arrivalrec.open("arrival_time.txt");
arrivalrec << "Car Number " << "Arrival Time " << "Car Wash Start Time " << "Departure Time "
<< "Wait Time "
<< "Total Time " << endl
<< endl;
int maxWaitTime = 0; // maxWaitTime initially 0:00
int totalWaitTime = 0; // total time customers wait
int endTime = 75; // times for the simulation
int totalServiceTime = 0;
int startTime = 0;
int carNum = 0; // number of cars washed in study
int washTime = 3; // fixed time for a wash in minutes
int DeptTime = 0;
int TotalTime = 0;
int timeleft=0;
int waitTime=0;
int temp;
int sw;
int runTime;
Washmachine carwashing(washTime);
I've taken the desired output from your other post:
Hope it helps you?
I am trying to compute the time history of the velocity described by the equation:
dV/dt = g − (C_d/m) * V^2. g = 9.81, m = 1.0, and C_d = 1.5.
To do this I need to create a program in c++ that uses the Euler explicit method to numerically solve the equation. I am trying to find the velocity from t = 0 to t = 1 seconds with three different step sizes of delta_t = 0.05, 0.1, and 0.2 seconds. And then you are supposed to show your percent error to the analytical solution given as: V(t) = sqrt((m*g)/C_d) * tanh(sqrt((g*C_d)/m) * t).
My problem is I am not sure how to iterate through Euler's method multiple times with different time intervals. So far I have solved the analytical equation, but am unsure where to go from here. If anyone could help point me in the right direction it would be greatly appreciated.
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;
int main() {
double m = 1.0; // units in [kg]
double g = 9.81; // units in [m/s^2]
double C_d = 1.5; // units in [kg/m]
double t; // units in [s]
double v; // units in [m/s]
cout << "The velocity will be examined from the time t = 0 to t = 1 seconds." << endl;
cout << "Please select either 0.05, 0.1, or 0.2 to be the time interval:" << endl;
cin >> t;
cout << "You have chosen the time interval of: " << t << " seconds." << endl;
v = sqrt((m * g) / C_d) * tanh(sqrt((g * C_d) / m) * t);
cout << "The velecity at a time of "<< t << " seconds is equal to: " << v << " m/s." << endl;
return 0;
} ```
If you want to iterate over t with increments of A, calculating the result of the formula with each t, you would write a for loop.
#include <iostream>
int main()
{
double m = 1.0; // units in [kg]
double g = 9.81; // units in [m/s^2]
double C_d = 1.5; // units in [kg/m]
std::cout << "The velocity will be examined from the time t = 0 to t = 1 seconds." << std::endl;
std::cout << "Please select the time interval:" << std::endl;
std::cout << "1: 0.05" << std::endl;
std::cout << "2: 0.1" << std::endl;
std::cout << "3: 0.2" << std::endl;
double A = 0; // increment in for loop
int x;
std::cin >> x;
switch (x) { // check what the input is equal to
case 1: A = 0.05; break;
case 2: A = 0.1; break;
case 3: A = 0.2; break;
default: std::cout << "Unknown option!" << std::endl; return 1;
}
std::cout << "You have chosen the time interval of: " << A << " seconds." << std::endl;
std::cout << "Results of V(t):" << std::endl;
// this initializes a variable t as 0,
//and while t is lower than or equal to 1,
//it will increment it by a and execute the logic within the scope of the loop.
for (double t = 0; t < (1 + A); t += A) {
std::cout << "at t = " << t << ": " << sqrt((m*g) / C_d) * tanh(sqrt((g*C_d) / m) * t) << std::endl;
}
return 0;
}
Refer to https://beginnersbook.com/2017/08/cpp-for-loop/ for more information. Note: I've also introduced a switch statement into the code to prevent unknown values from being input. https://beginnersbook.com/2017/08/cpp-switch-case/
Let me preface this by saying I'm still extremely new to C++ and want to keep things as simple as possible. I'm also pretty terrible at math.
Mostly, I'm looking to see if anyone can help my code so it will always give the correct result. I've mostly got it to do what I want, except in one scenario.
My code is trying to find out how many packages of hotdog weiners and how many packages of hotdog buns someone has purchased. Then it tells the user how many hotdogs they can make from that as well as how much leftover weiners or buns they would have. Assuming a package of weiners contains 12 and a package of buns contains 8, this is what I have come up with so far:
#include <iostream>
#include <cmath>
using namespace std;
void hotdog(int a, int b){ //a = weiner packages, b = bun packages
int weiners = 12 * a;
int buns = 8 * b;
int total = (weiners + buns) - (weiners - buns);
int leftOverWeiners = total % weiners;
int leftOverBuns = total % buns;
int totalHotDogs = total / 2;
cout << "You can make " << totalHotDogs << " hotdogs!" << endl;
if (leftOverWeiners > 0){
cout << "You have " << leftOverWeiners << " weiners left over though." << endl;
}else if (leftOverBuns > 0){
cout << "You have " << leftOverBuns << " buns left over though." << endl;
}
}
int main(){
int a;
int b;
cout << "Let's see how many hotdogs you can make!" << endl;
cout << "How many weiner packages did you purchase?: ";
cin >> a;
cout << "How many bun packages did you purchase?: ";
cin >> b;
hotdog(a, b);
return 0;
}
With this, I can always get the correct answer if the ratio of buns to weiners is the same or if there are more weiners than buns.
Because of the way I've set up total and/or leftOverBuns (lines 9, 11), I will never get the correct answer to how many left over buns there will be. I know there must be a simpler way to do this if not a way to modify my current code but I am stumped.
I know I left virtually zero notation, so if you would like some please let me know!
You're making it too complicated. Try this:
if(weiners > buns)
{
cout << "You can make " << buns << " hotdogs!" << endl;
cout << "with " << weiners-buns << " weiners left over" << endl;
return;
}
cout << "You can make " << weiners << " hotdogs!" << endl;
if(buns > weiners)
{
cout << "with " << buns-weiners << " buns left over" << endl;
}
The smaller of {buns, weiners} is the number of hot dogs, and the if-then blocks determine whether the function will report leftover buns or weiners.
#include <iostream>
void hotdog( int weinerspackages, int bunspackages ){
const int weinersPerPackage = 12;
const int bunsPerPackage = 8;
const int totalweiners = weinerspackages * weinersPerPackage;
const int totalbuns = bunspackages * bunsPerPackage;
int leftoverweiners = 0;
int leftoverbuns = 0;
int amountOfHotdogs = 0;
if( totalweiners > totalbuns ){
leftoverweiners = totalweiners - totalbuns;
amountOfHotdogs = totalbuns;
leftoverbuns = 0;
}
else if( totalbuns > totalweiners ){
leftoverbuns = totalbuns - totalweiners;
amountOfHotdogs = totalweiners;
leftoverweiners = 0;
}
else{
amountOfHotdogs = totalweiners;
leftoverweiners = 0;
leftoverbuns = 0;
}
std::cout << "You can make: " << amountOfHotdogs << " Hotdogs" << std::endl;
std::cout << "Leftover Weiners: " << leftoverweiners << " || Leftover Buns: " << leftoverbuns << std::endl;
}
int main(){
int PackagesW = 8;
int PackagesB = 12;
hotdog( PackagesW, PackagesB );
system("pause");
return 0;
}
Note: It is possible to do this with less variables, I declared this amount of variables to make it easier to understand what the numbers represent.
Assuming that it only takes one of each to make a hotdog, you can find which of the ingredients you have the least, and the amount of hotdogs you can make will be limited by the amount of that ingredient, that is why amountOfHotdogs takes the value of the lesser one. If both are equal in amount, then amountOfHotdogs can take the amount of either.
Only the ingredient with the larger amount will have leftovers, therefore leftoverweiners = totalweiners - totalbuns; when totalweiners > totalbuns and vice-versa.
I've been having a slight issue with my program, what I'm trying to do is develop a way for users to simulate the possible strengths of passwords. This is assuming that all passwords are permutations (weird I know, but I presume that this is to stop data from becoming even more unwieldy.) using the equation...
//n!/(n-r)! when n! = (e^-n)*(n^n) sqrt(2(pi)n). When n is number of characters in use and r is length of password
No matter what I put I receive nan as an answer. I thought that perhaps my equation was off (maybe somehow I was dividing by zero) so I reworked it and simplified it a great deal. But that didn't seem to be the problem, though I feel that this got me closer to being correct. But I had the thought that maybe numeric overflow is having an effect here? But I really don't know how to fix something like that. I tried jumping from different data types but nothing seemed to work.
I have a problem with the modulus too. It returns back numbers less than zero for time, so with my noobish knowledge that tells me that maybe I'm overflowing it again but how else am I going to use % without defining it as an int? Maybe fixing the above problem will work out this one?
I would be beyond grateful for any help given to me. How does one go about dealing with return values of nan? Is there a step by step status quo for solving it? Is it pretty much always overflow or could it be something else?
The code itself.
#include <iostream>
#include <cmath>
using namespace std;
const int SECONDS_IN_YEAR = 31556926;
const int SECONDS_IN_DAY = 86400;
const int SECONDS_IN_HOUR = 3600;
const int SECONDS_IN_MIN = 60;
int main()
{
int passwordLength ,characterSymbols;
double instructionsPerSecond, instructionSuccess;
////////////////////////////////////////////////////////////////////////////////
//Equations needed
// n!/(n-r)!
//n is the number of letters in the alphabet
//and r is the number of letters in the password
// n! = (e^-n)*(n^n) sqrt(2(pi)n)
double numeratorFactorial = (pow(M_E,-characterSymbols))
*(pow(characterSymbols,characterSymbols))
*(sqrt(2*M_PI*characterSymbols));
// (n-r)
double characterMinusLength= (characterSymbols-passwordLength);
// (n-r)! = (e^-(n-r)) * ((n-r)^(n-r)) * sqrt(2(pi)(n-r))
double denominatorFactorial = ((pow(M_E, -(characterMinusLength)))*
(pow((characterMinusLength),(characterMinusLength)))
* (sqrt(2*M_PI*(characterMinusLength))));
// n!/(n-r)!
long double passwordPermutation = (numeratorFactorial / denominatorFactorial);
// (passwords)* (instructions/Password) * (seconds/instruction) = sec
int passwordSeconds = (passwordPermutation * instructionSuccess)
*(1/instructionsPerSecond);
int passwordMin = passwordSeconds / SECONDS_IN_MIN ;
int passwordHour = passwordSeconds / SECONDS_IN_HOUR;
int passwordDay = passwordSeconds / SECONDS_IN_DAY ;
int passwordYear = passwordSeconds / SECONDS_IN_YEAR;
////////////////////////////////////////////////////////////////////////////////
//Explain purpose of program
cout << "This program is designed to simulate the strength of passwords." << endl;
//Ask for alphabet
cout << "But first, share with me the max number of characters you'd be using."
<< endl;
cin >> characterSymbols;
//Reflect information
cout << "We will be using " << characterSymbols << " character symbols to "
<< " construct the password.\n" << endl;
///////////////////////////////////////////////////////////////////////////////
//Input length of password
cout << "\n\nWill you give me the length of proposed password?" << endl;
cin >> passwordLength;
//Repeat information
cout << "The password length will be " << passwordLength << "." <<endl;
//cout permutations
cout << "This would lead to " << passwordPermutation << " unique password\n"
<< endl;
////////////////////////////////////////////////////////////////////////////////
//Ask for computer strength
cout << "How powerful is this computer? How many instructions per second " << endl;
cout << "can it accomplish?" << endl;
cin >> instructionsPerSecond;
//Read out computer strength
cout << "The computer can do " << instructionsPerSecond << " instructions/second"
<< endl << endl;
////////////////////////////////////////////////////////////////////////////////
//Ask for instructions/password
cout << "The number of instructions needed to test your password is." << endl
<< endl;
cin >> instructionSuccess;
//reflect
cout << "This computer can do " << instructionSuccess
<< " instructions/password" << endl;
////////////////////////////////////////////////////////////////////////////////
cout << "\n\nThe amount of seconds it'll take to crack this passcode is... "
<< endl << passwordSeconds << " seconds.\n\n\n\n\n" << endl;
////////////////////////////////////////////////////////////////////////////////
//Reflect all information in an easily readable table
cout << "Number of character symbols using... " << characterSymbols << endl;
cout << "Length of password... " << passwordLength << endl;
cout << "Number of permutations... " << passwordPermutation << endl;
cout << "Instructions per second... " << instructionsPerSecond << endl;
cout << "Instructions per password..." << instructionSuccess << endl;
cout << endl << endl << endl;
////////////////////////////////////////////////////////////////////////////////
//Add in conversions for min, hour, day, years
cout << "Number of seconds to break..." << passwordSeconds << endl;
cout << "Converted to minutes..." << passwordMin << endl;
passwordMin = passwordSeconds / SECONDS_IN_MIN;
passwordSeconds = passwordSeconds % SECONDS_IN_MIN;
cout << "Converted to hours..." << passwordHour << endl;
passwordHour = passwordSeconds / SECONDS_IN_HOUR;
passwordSeconds = passwordSeconds % SECONDS_IN_MIN;
cout << "Converted to days..." << passwordDay << endl;
passwordDay = passwordSeconds / SECONDS_IN_DAY;
passwordSeconds = passwordSeconds % SECONDS_IN_DAY;
cout << "Converted to years..." << passwordYear << endl;
passwordYear = passwordSeconds / SECONDS_IN_YEAR;
passwordSeconds = passwordSeconds % SECONDS_IN_YEAR;
return (0);
}
"nan" stands for "not a number". This is happening because you have declared the variables characterSymbols and passwordLength without giving them an initial value.
You must initialize any variable before you use it - if you don't then you will have undetermined behavior. For example:
int x;
int y;
int z = x + y;
There is no way to predict what z will be equal to here because we don't know what x or y are equal to. In the same way, your code should be something like:
int characterSymbols = 10; //or whatever you want the initial value to be
...
double numeratorFactorial = (pow(M_E,-characterSymbols))
*(pow(characterSymbols,characterSymbols))
*(sqrt(2*M_PI*characterSymbols));
In this way, numeratorFactorial will have a valid value.
It appears you think you are declaring "equations" when you are actually declaring variables. You write:
double numeratorFactorial = (pow(M_E,-characterSymbols))
*(pow(characterSymbols,characterSymbols))
*(sqrt(2*M_PI*characterSymbols));
But characterSymbols isn't defined, only "declared". characterSymbols is declared above it, but it doesn't have a value... yet. Later on you use cin to get a value into it, but when you first declare numeratorFactorial you can't simply expect the program to insert the value into numeratorFactorial when characterSymbols changes.
Some definitions are probably in order: The statement double numeratorFactorial = some_value; creates a variable named numeratorFactorial and uses some_value to fill that variable immediately. What you want is a function, a logical statement that you can "pass values" to so values are generated when you need them. For example, for your numerator factorial:
double numeratorFactorial(double characterSymbols) {
return (pow(M_E,-characterSymbols))
*(pow(characterSymbols,characterSymbols))
*(sqrt(2*M_PI*characterSymbols));
}
int main() {
std::cout << "Numerator Factorial test: " << numeratorFactorial(5.0) << std::endl;
}
Note that you cannot declare a function within the main function.
This sort of thing is programming fundamentals, and it seems like you are trying to run before you've learned to walk. Get a good book like C++ Primer and pace yourself.