| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I got a simple problem and yet I can't fix it
![]() Here is some fast code (not in the program but probably explains it better) Code:
// This is one a .h file.
int After(Income)
{
int p =0;
if (Income == 1)
{p = 2;}
else if (Income == 2)
{ p = 4;}
else if (Income == 3)
{ p = 34;}
and so one...
cout << p;
}
int BigNum(MoreNum) // There I changed it now and
// thanks for telling me
{
int Big = 0;
Big += MoreNum;
After(Big);
}
// Now this is one is a .cpp file
int main()
{
int q =0;
int w =0;
int r = 0;
cout<< "Enter one number at a time"
cout<< "Enter first number:"
cin>> q;
BigNum(q);
cout<<"Enter second number:"
cin>> w;
BigNum(w);
cout << "Enter third number:"
cin>> r;
BigNum(r);
return 0;
}
So I hope you get the idea. You enter numbers and they need to add themselves up and then do the other thing and this code just tells to show int p. My code is very like this one. And it compiles without a problem but my problem is that they don't add up. For example: I said the first int to 2 and the outcome works fine. It shows the right integers. Then I type the second int to 7 the outcome would be like if I wanted a 7 but I want a outcome of a 9 cause of the first 2 that I typed in. And for the third number I put it to a 4 and then I get the outcome of a 4 instead of the 13. I hope you guys get the idea. I need some advice of this. I looked at one book for help but it doesn't help me in this topic. I ran out of guesses and methods of fixing this. So someone plz help. Last edited by BloodlustShaman : March 18th, 2006 at 10:04 PM. |
|
#2
|
|||
|
|||
|
I haven't looked at your code in detail, but what I noticed at first sight:
Code:
int After(Income) Code:
int BigNum(MoreNum); You have to specify the variable type that a function accepts. Furthermore, your second function is only a declaration without a definition - i suppose you put the ';' accidentally, so, remove them. That means your functions should be: Code:
int After(int Income) Code:
int BigNum(int MoreNum) Good luck ![]() |
|
#3
|
|||
|
|||
|
Quote:
There is something more to what ossinator pointed out.In order to maintain the previous sum you should declare variables as "Static" instead of an automatic variable. A static variable stores the previous contents. Thus what ever is your variable sum, declare it as a static integer rather than an integer. |
|
#4
|
|||
|
|||
|
Quote:
Oh srry I put that in but thats not my problem I need to change that. I accidently did put that in but thats not in my real program cause as I said it shows me no warnings nor errors and it compiles it right. Whats wrong is how I code and what I want to do. I got to change that but thanks for telling me that part ![]() |
|
#5
|
|||
|
|||
|
Quote:
Told you earlier to declare your sum variable as static integer instead of plain integer. |
|
#6
|
|||
|
|||
|
Quote:
Yeah I know I saw that but dude coding is my hobby for now and I had to go I saw your post and sorry about acting like I ignore it but I am busy with homework. I am going to do that later and sorry about acting like I ignore you but these couple of days I have been too busy and lately I get in and out of these furoms and only have like 3 mins to see the stuff. But I'll do that and thanks for the help. ![]() |
|
#7
|
|||
|
|||
|
Quote:
I am not taking that seriously.I thought that you missed my earlier reply. Anyway what other issues are you facing? |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Int problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|