Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Practices [2] + Source

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Up2Admin
I'm a spammer
Reputation: 126

Joined: 17 Oct 2007
Posts: 6548
Location: Texas

PostPosted: Sun Aug 02, 2009 11:11 pm    Post subject: [C++] Practices [2] + Source Reply with quote

Well, I'm getting real into C++, totally hooked. Just started today and I've come up with 2 crappy practice programs.
If anyone wishes to provide me with any help, I'm available on MSN.
[email protected]


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1. First Project
Source as Text

What's it do?
The user enters a number into the dialog and presses the enter key, then the dialog displays:
Code:
"20+*user number*=*sum of the integers*

It then displays whether the sum is greater than, less than, or equal to 100.

The exe can be found in the Debug folder.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2. Calculator
Source as Text

What's it do?
What do you think...


The exe can be found in the Debug folder.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

_________________
Back to top
View user's profile Send private message Visit poster's website
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon Aug 03, 2009 4:59 am    Post subject: Reply with quote

At the end of both your sources you do: "return main();" to restart the program. You shouldn't do that because after it has been run a lot of times this will cause a stack overflow. Instead, if you want your app to repeatedly do those actions you should put it in a loop like this:

Code:
#include "stdafx.h"
#include <iostream>

using namespace std;

int main(void){
   bool Exit = false;
   
   while(Exit == false){
      
      int a = 20;
      int c;
      int final;
      //The variables are defined
      
      cout << "Enter a number:";
      cin >> c;
      final = c+a;
      //User input is created and the variable 'final' is assigned a new value
      
      cout << a << "+" << c << "=" << c + a << "\n";
      //Outputs: 20 plus the users input value and what it's equal to
      
      if(final>100){
         cout << final << " is more than 100" << "\n";
      }else if(final==100){
         cout << final << " is equal to 100" << "\n";
      }else{
         cout << final << " is less than 100" << "\n";
      }
      //Determines whether the final value is less than, equal to, or greater than 100
      
      cout << "\n";
      //Creates a new line
      
      cout << "Enter 1 to rerun the program, or any other number to exit." << "\n";
      cin >> final;
      //Used the 'final' variable here since it's not used anymore so you don't have to make a new variable.
      
      if( final != 1 ){
         Exit = true;
         //You can also use  break;  here to exit the loop
      }
   }
}
Back to top
View user's profile Send private message
Up2Admin
I'm a spammer
Reputation: 126

Joined: 17 Oct 2007
Posts: 6548
Location: Texas

PostPosted: Mon Aug 03, 2009 12:16 pm    Post subject: Reply with quote

Thanks for the info! I'll use that method from now on Very Happy
_________________
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites