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++ query.
Goto page Previous  1, 2
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Tue Jan 22, 2008 8:48 pm    Post subject: Reply with quote

Cx wrote:
Haha.
Funny how constructive people can be (and correctly so) about a simple console number addition program.


i completely edited since last night lol. i learned and did it all by myself Very Happy.
heres my new code.
this adds 3numbers and divides by 3 to find average.

Code:

#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int num1, num2, num3, num4;
    num4 = 3;
    cout << "Enter your first number" << endl;
    cin >> num1;
    cout << "Enter your second number" << endl;
    cin >> num2;
    cout << "Enter your third number" << endl;
    cin >> num3;
    cout << "The average of your numbers" << "=" << (num1+num2+num3) /num4 << endl;
    cin.ignore();
    cin.get();
    return 0;
}
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Tue Jan 22, 2008 8:57 pm    Post subject: Reply with quote

Why are you including cstdlib? You don't need it.. And you don't need to declare num4. You can just put / 3 instead. Also, don't use cin.get(), just use cin.sync() with ignore. Like this:

Code:
#include <windows.h>
#include <iostream>

int main()
{
   int iNum1, iNum2, iNum3;

   std::cout << "Enter your first number: ";
   std::cin >> iNum1;

   std::cout << std::endl << "Enter your second number: ";
   std::cin >> iNum2;

   std::cout << std::endl << "Enter your third number: ";
   std::cin >> iNum3;

   std::cout << std::endl << "The average of your numbers is: " << ((iNum1+iNum2+iNum3)/3);

   std::cin.sync();
   std::cin.ignore();
   return ERROR_SUCCESS;
}

_________________
- Retired.
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
Goto page Previous  1, 2
Page 2 of 2

 
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