Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C++/C Programming › Simple c++ help needed

Simple c++ help needed

Posts 1–15 of 21 · Page 1 of 2
HO
hobosrock696
Simple c++ help needed
I'm pretty sure there is a very simple way to do this but I haven't found a good explanation for how to do it. How would I go about getting an input from a user that I can verify is an integer?

One other question I have is related to code similar to this:
Code:
int factor(long innum)
{
	int prev = 0;
	ofstream factors;
	factors.open("factors.txt");
	if (factors.is_open())
	{
		factors << "Factors of " << innum << ":" << endl << endl;
		for (long loops = 1; loops <= innum; loops++)
		{
			if (innum % loops == 0)
			{
				factors << loops << " ";
				prev++;
			}
			if (prev == 7)
			{
				factors << endl;
				prev = 0;
			}
		}
	}
	else
	{
		clearscreen
		wait
		cout << "Error opening file!!!" << endl << "Exiting...";
		return(1);
	}
	factors.close();
	return(0);
}
Now thats the code I have for finding factors of a number. I would want to add a percent type thing to it but I'm not sure how I would do that. I could divide 'loops' by 'innum' but how could I control how many decimal places are kept if i wanted to display something like xx.xx%

Thanks for any help in advance
#1 · 15y ago
WH
whit
char f;
cin >> f;

Oh Wait You Want Integer so It Would Be int f;
cin >> f;
#2 · edited 15y ago · 15y ago
HO
hobosrock696
Yea but now how do I now take it so it can be manipulated as a number and how do I verify there are no letters in it?

Edit: I wrote that code myself I do know what I am doing to this level I am asking how do I get input from the user and extract a number from it but also making sure that nothing but numbers were typed,
#3 · 15y ago
WH
whit
Quote Originally Posted by hobosrock696 View Post
Yea but now how do I now take it so it can be manipulated as a number and how do I verify there are no letters in it?

Edit: I wrote that code myself I do know what I am doing to this level I am asking how do I get input from the user and extract a number from it but also making sure that nothing but numbers were typed,
Soon As They Type In The Integer For f Its Goin to Be Saved In So Yea
#4 · 15y ago
doofbla
doofbla
I think he want to make sure that the user don't type in a letter or smth.

One Solution:
Code:
 char input;
cin>>input;
testinputaboutascii();
Convert char to int (sprintf should work)
i think this is ONE solution but there should be millions of ways you could do it

ASCII codes allows would be 0x41 - 0x5A (A-Z) and 0x61 - 0x7A (a-z)

check the char input with a pointer the the char and then go one step forward
if(*char==......)
char++;
#5 · edited 15y ago · 15y ago
WH
whit
Quote Originally Posted by doofbla View Post
I think he want to make sure that the user don't type in a letter or smth.

One Solution:
Code:
 char input;
cin>>input;
testinputaboutascii();
Convert char to int (sprintf should work)
i think this is ONE solution but there should be millions of ways you could do it

ASCII codes allows would be 0x41 - 0x5A (A-Z) and 0x61 - 0x7A (a-z)

check the char input with a pointer the the char and then go one step forward
if(*char==......)
char++;
He Said He Was No0b He Isnt Goin To Know How Too Do All That...Atleast I Think
#6 · 15y ago
doofbla
doofbla
Quote Originally Posted by whit View Post


He Said He Was No0b He Isnt Goin To Know How Too Do All That...Atleast I Think
Ah ok I didn't think about that so.. ty.

Anyhow I've a new idea how to do:

Maybe you can just disable all keys instead of 0-9 for the time of input

There are tons of ways
#7 · edited 15y ago · 15y ago
HO
hobosrock696
I have done pointers and memory all that jazz im not great with it but this I can handle. Yes I consider myself a noob and will continue to until I know c++ very well and at least a bit of the windows api + direct x

Question:

Would I check for ascii? Or is it unicode? Is it different for linux or for macs?
#8 · edited 15y ago · 15y ago
HO
hobosrock696
Ok so I tried writing some code but obviosly im doing something wrong since it doesnt work. Here it is....
Code:
// testingchar.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
	char * input = "a";
	int counter = 0;
	cin.getline(input, 20);
	while (input != "\0")
	{
		cout << input[counter] << endl;
		counter++;
	}
	return 0;
}
Oh my noob self forgot to add the * before the pointer. Problem is It still wont compile... Anyone willing to write this into a WORKING example XD and thanks for any help once again!
#9 · edited 15y ago · 15y ago
TO
Toxic Waltz
Quote Originally Posted by hobosrock696 View Post
Ok so I tried writing some code but obviosly im doing something wrong since it doesnt work. Here it is....
Code:
// testingchar.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
	char * input = "a";
	int counter = 0;
	cin.getline(input, 20);
	while (input != "\0")
	{
		cout << input[counter] << endl;
		counter++;
	}
	return 0;
}
Oh my noob self forgot to add the * before the pointer. Problem is It still wont compile... Anyone willing to write this into a WORKING example XD and thanks for any help once again!
define input as an array.
char only holds 1 character
#10 · 15y ago
doofbla
doofbla
Ok i made it for you -.- but i think next time you should show more self engagement:
Code:
#include "windows.h"
#include "stdio.h"
#include "iostream"

using namespace std;

char input[20];

bool checkchar(char * in)
{
    while(*in != 0)
    {
        if(*in < 0x30 || *in > 0x39)
        {
            return false;
        }
        in++;
    }
    return true;
}

int main()
{
    cin.getline(input, 20);

    if(checkchar(input))
    {
        cout<<"You entered only numbers - OK"<<endl;
    }
    else
    {
        cout<<"You entered NOT only numbers - FAIL"<<endl;
    }

    system("PAUSE");
    return 0;
}
with this you can proof if the user entered only numbers -> in ASCII it works
#11 · 15y ago
HO
hobosrock696
Thanks and well this is why I am a noob. Also yes thats true I didnt think about that much I apologize for being.... a sort of leecher in this case

Edit: Shouldnt you also not be checking for 0 but "\0" which signifies the end of a string of chars? Or is that just me being wrong?
#12 · edited 15y ago · 15y ago
Sixx93
Sixx93
just make a for cicle and check if the variable of the loop is equal to your imput, like:

int f;

cin>>f;

for(int j=0; j<10; j++)
if(f==j)
//it's a number
#13 · 15y ago
HO
hobosrock696
Yea I was looking at the code. I'm assuming the compiler would optimize that into the same code in the end but I still prefer a for over a while loop in which a variable is incremented.
#14 · 15y ago
doofbla
doofbla
Quote Originally Posted by hobosrock696 View Post
Thanks and well this is why I am a noob. Also yes thats true I didnt think about that much I apologize for being.... a sort of leecher in this case

Edit: Shouldnt you also not be checking for 0 but "\0" which signifies the end of a string of chars? Or is that just me being wrong?
0x48 = 0
0x49 = 1
.
.
.
0x57 = 9

0x0 is a what you get whan you press SPACE
#15 · 15y ago
Posts 1–15 of 21 · Page 1 of 2

Post a Reply

Similar Threads

  • Simple Chams Help Needed Plz.By donbiggy in Combat Arms Hacks & Cheats
    1Last post 17y ago
  • Some help neededBy Julma Henri in Combat Arms Mod Help
    0Last post 15y ago
  • Help needed!By FailBladez in Combat Arms Help
    8Last post 15y ago
  • Texture won't work, help needed :(By Kikimo900 in Combat Arms Mod Help
    1Last post 15y ago
  • Help Needed with injecting hacks?By ShoeStrinqs in CrossFire Help
    3Last post 15y ago

Tags for this Thread

None