function or eqation error

the program has no error's when i compile but the problem is still not doing what i want it to do. it should work like this, i enter a number of days then the program is to add twice the amount each day but i keep getting crazy numbers and the total always says i have earned one $1.

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//this program doubles the users ammount of money daily then shows it on screen.
//I the days where input into the problem .
//P the days are presented then each ammount for each day is multiplide.
//O the out put are the days multiplide.


int Get_massage1()
{

cout <<"please enter the days you wish to add" <<endl;
return 0;
}


int Get_massage2(int days)
{

int total;
double pennies = 0.0;
const one = {1},zero = {0};
cin >> days;
if (days <= zero)
cout <<"Error your doing it wrong, please enter a positive number"<<endl;
cout << "days / number of pennies " <<endl;
cout << "_________________________" <<endl;
cout<<"days "<< pennies+1 << "\t\t" <<"Salery 1" << endl;
for (pennies = one; pennies < days; pennies++)
cout<<"days "<< pennies+1 << "\t\t" <<"Salery "<< ( pow(2,pennies))<< endl;
total=pow( 2,pennies);

return 0;
}

int Get_massage3()
{
int days=0,total=1;
double pennies= 0.0;
const one = {1},zero = {0};
pennies += days;
cout <<fixed <<showpoint <<setprecision(2);
cout <<"the total amount of money made is: $"<<total<<endl;
return 0;
}


int main()
{
int days;
days = Get_massage1();
Get_massage2(days);
Get_massage3();
return 0;
}
Please use the code-brackets!

First:
In Get_message2 you try to calculate the salery. The problem is that you do not write the new amount into your variable. so, I guess, you get the same salery in each line.

Second

If you want to double something, you must not raise it to the second power. You must multiply it like result = amount * 2^n (this is not the code, rather the mathematical expression) because frankly:

Third:
I do not quite grasp the use of the variables.

Fourth:
in Get_Message3 you explicitely set "total = 1". hat's why your result is 1.

Fifth:

in Get-Message1 you prompt
 
return 0;

This will return the value ZERO, meaning your variable days will always be set to zero.
Same goes for total in Get_message2().

I think there are other bugs but first you should clean up the math-part.
then you should think about which function should return what value and which function needs which parameter in order to give thise value back something back.

happy hunting

int main
Carring on from the previous post and the variables....
It looks like you are having problems with scope, and the way you are passing variables into and out of functions.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
   int days;
    days = Get_massage1();   // days is set to return value from Get_massage1() i.e. 0

   // Pass  a copy of the current value of variable days to Get_massage2() i.e. 0
   Get_massage2(days);

   // You only passed a copy of days to Get_massage2() so
   // all the changes made to days in Get_massage2() are now lost, days is still zero
   Get_massage3();  // has its own local copy of days which is set to 0 and local copy of total
                                    // which is set to one, hence constant result of $1 
   return 0;
}


Setting days to the return value of Get_massage1() is a bit pointless but it is initialising days to zero, I suspect this is more by accident than design. I would move

1
2
3
cin >> days;
if (days <= zero)
cout <<"Error your doing it wrong, please enter a positive number"<<endl;


into Get_massage1() and put it in a loop so that it keeps asking until the user puts in a positive number. At the end of the function use
return days rather than return 0 which will pass the value entered, back to main()

You then need to pass total back out of Get_massage2() so
return total rather than return 0 and create a variable in main to receive it.

Finally pass both days and total into Get_massage3() and remove the local copies of these variables.

I hope you followed that, I haven't done the code for you so that you can have a go yourself. Ask more questions if you need to

... and as int main said please use the code tags, it makes it much easier to read, see this article if you're not sure how http://www.cplusplus.com/forum/articles/1624/

Topic archived. No new replies allowed.