How to switch from ...
 
Notifications
Clear all

How to switch from Character to Integer - Ascii - Capitalize/Uncapitalize Letters


Posts: 0
Topic starter
(@Tonakai)
New Member
Joined: 10 years ago

Here we go,there's a script i've made in C++.

The script it's very simple and "Noob Friendly".

All the script does it's asking a letter in input and gives out that letter Capitalized/Uncapitalized.
You can do it using Ascii Table and 2 variables,one Integer and one Character.
You can also use a switch case function but it's a bit stupid,you'll waste time for nothing.

//
	//  main.cpp
	//  charset
	//
	//  Created by Cris on 06/05/15.
	//  Copyright (c) 2015 Cris. All rights reserved.
	//
	
	#include //Library for C++
	using namespace std;
	int main()//Main function,runs from the start,other functions need to be called
	{
	    char carattere; //Set char for variable "carattere"
	    cout<>carattere;//Input
	    int a ;//Set integer for variable "a"
	    a = carattere;//The letter goes from Character to Integer
	    if (a >= 97){ //Condition,in Ascii numbers with 97+ means they're uncapitalized letters.
	        //This condition applies if a letter is Uncapitalized
	        a = a - 32; //There are 32 spaces between Capitalized and Uncapitalized letters.
	        carattere = a;//The letter from Integer goes back to Character
	        cout<<"Letter become: "<<carattere;}//Stamp
	    else { a = a + 32;//If the letter is already Capitalized adds 32 positions and changes it
	        carattere = a;//Switch
	        cout<<"Letter become: "<<carattere;}//Stamp
	    return 0;//Pause the script
	}
	
	

P.S. The code isn't in PHP,i did it to highlight the things a bit 🙂

Made it with XCode but you can use Sublime Text,Geany,Compile C and many others.

Reply
Name of the Video Game, and any other Tags