C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 18th, 2006, 02:09 AM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Post Int problem

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.

Reply With Quote
  #2  
Old March 18th, 2006, 03:21 AM
ossinator ossinator is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 40 ossinator User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 6 h 11 m 12 sec
Reputation Power: 4
Send a message via ICQ to ossinator
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

Reply With Quote
  #3  
Old March 18th, 2006, 06:17 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by BloodlustShaman
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);
{
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.


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.

Reply With Quote
  #4  
Old March 18th, 2006, 10:01 PM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by ossinator
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


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

Reply With Quote
  #5  
Old March 19th, 2006, 06:29 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by BloodlustShaman
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


Told you earlier to declare your sum variable as static integer instead of plain integer.

Reply With Quote
  #6  
Old March 19th, 2006, 11:35 AM
BloodlustShaman BloodlustShaman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: in earth
Posts: 176 BloodlustShaman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 12 h 9 m 3 sec
Reputation Power: 4
Send a message via Yahoo to BloodlustShaman
Quote:
Originally Posted by Cirus
Told you earlier to declare your sum variable as static integer instead of plain integer.


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.

Reply With Quote
  #7  
Old March 19th, 2006, 01:51 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by BloodlustShaman
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.


I am not taking that seriously.I thought that you missed my earlier reply. Anyway what other issues are you facing?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Int problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT