Jump to content

Recommended Posts

Posted

Here is my code...

#include <iostream>

using namespace std;

void main() {

   int year;

   cout << "Please give a year " << endl;
   cin >> year;

   cout << "\n You Entered: " << year;

}

 

Well... that i want is the length of year max 4 numbers, anyone can help me?

 

I dont want this way..

 

if (year > 9999) 
{
    //Code
}

 

 

im new in c++, i try year.length(); ... but dont work.... and visual studio dont help in code syntact... i mean dont show you what must do like c# or simple vb project....

 

Soz for my bad english..

 

Posted

if(year.length()!=4)

{

  cout <<"Wrong year value"<< endl;

}

else

{

  cout <<"Correct...(4 digits)"<< endl;

}

 

I'm not sure if it works on integers...but you can set year as string.

Posted

Alright.

this program gets strYear. if strYear is max 4 digits it checks if it really is a number.If it is a number it converts it to integer in intYear. +outputs messages

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
int intYear;
string strYear;
cout <<"Value for strYear:";
cin >> strYear;
if(strYear.length()<=4)
{
	stringstream sti(strYear);
	sti >> 	intYear;   //this should be two lines lower but there's a problem with the if...nvm it works like this too
	if(intYear==0)
	{
		cout<<"Wrong year input...use numbers!";
	}
	else
	{
		cout<<"strYear is <= 4 digits, converting it to integer in variable intYear..."<<endl;
	}
}
else
{
	cout<<"Wrong year input.(must be < 9999)"<<endl;
}
return 0;
}

 

 

or hell of easier:

 

#include <iostream>
using namespace std;

int main()
{
int year;
cin << year;
if((year>0)&&(year<9999))
{
	//code
}
else
{
	cout<<"Wrong year!";
}
return 0;
}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Skylord  = L2Gold.eu ;   Skylord is the programmer at L2Devs. Look what he posted in my thread. I reported him, and they automatically deleted his post and closed my thread.   They need to trick people into buying this garbage.   You can safely use this extender:   https://maxcheaters.com/topic/253977-%F0%9F%94%A5-l2ext-custom-interlude-vang-%E2%80%93-2026-release/  
    • 💙 PRIDE ESSENCE X1  ✅ Start: 14.03.2026  ✅ UPDATE: SAMURAI CROW  ✅ ONLINE: 2000+  💜 NO P2W / BIG CLANS / INTERNATIONAL COMMUNITY / STAGE SYSTEM  🎮 Discord bonus: https://discord.gg/prideessence Pride Essence Official Server Wiki Here you can find all features, systems, and detailed information to fully understand the server.   - General Features - https://prideessence.club/general-features - Road Map - https://prideessence.club/roadmap/ - Class Balance – 14/03 - https://prideessence.club/class-balance-14-03/ - Referral System - https://prideessence.club/referral-system/ - Party Synergy System - https://prideessence.club/party-synergy-system/ - Dual Class System - https://prideessence.club/dual-class-system-3/ - Premium Account - https://prideessence.club/premium-account/ - Game Store - https://prideessence.club/game-store/ - L-Coin Store - https://prideessence.club/l-coin-store/ - Command Channel Skill Availability - https://prideessence.club/command-channel-skill-availability/ - Clan DKP System - https://prideessence.club/clan-dkp-system/ - Target Priority System - https://prideessence.club/target-priority-system/ - Skins - https://prideessence.club/skins/ - Players Inspect - https://prideessence.club/players-inspect/ - Gear Score Ranking - https://prideessence.club/gear-score-ranking/ - Guaranteed Enchant System - https://prideessence.club/guaranteed-enchant-system/ - Account Shield - https://prideessence.club/account-shield/ - VIP Level Ranking - https://prideessence.club/vip-level-ranking/ - Tournament - https://prideessence.club/tournament-2/ - Fortress Siege - https://prideessence.club/fortress-siege/ - Olympiad - https://prideessence.club/olympiad/ - Enchant and Compound Limit - https://prideessence.club/enchant-and-compound-limit/ - Enchant Rates - https://prideessence.club/enchant-rates/ - Pride World Marketplace - https://prideessence.club/pride-world-marketplace/ - Raid Boss Lootbox - https://prideessence.club/raid-boss-lootbox/
    • Dunno this mxc tricky website scammers everywhere.
    • ***DO NOT BUY WHAT IS POSTED HERE FOR FREE*** https://www.mediafire.com/file/mhjiaoipe6hohjm/Extender_Rev_222_by_Guytis.rar/file   It has everything Devs is offering for $450 USD with a license. Here it is, free and with source code. 
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..