-
Encryption problem!!
hey guys, im a newbie who has just started programmin. i recieved a homework question which has something to do with this..
"The program has to ask a user to enter their name, and the output will be :
User entered david.. the output will be:
i) The ascii value for D is 68, a 97, v 118, i 105, d 100
ii)68 in binary is 10001000
97 in binary is 1100001
etc....
iii) the number of ones in the binary code for david is 2,3 etc.. and this number can be joined as 23etc....
iv)reading this number right to left gives us etc32...which can be converted to binary.
v)then this number in decimal would be.....
vi)then adding the decimal numbers together will give us a number.. then adding both numbers in that number together will give us the answer.
thats it for now.. if any1 can help me thru this or if i cud get sum ideas on where to start.. nething would be appreciated..
thanks in advanced :)
-
-
umm not really.. dont really kno where to start.. i guess i could look it up in google but i want to understand it. know what i mean
-
Have you tried casting individual chars to int?
-
I,
Code:
string Name = "";
cout<< "Enter your name - ";
cin >> Name;
for ( int i=0; i<(int)Name.size(); i++ )
{
cout<< '\n' << (int)Name[i];
}
for most of the rest, look into <bitset>
-
Show some code, we'll talk later.
-
I don't see how you need our help, your post is already encrapped as it is.
Read me.
-
ok guys i will post some code for help.. thanks in advanced :)
-
basically this is what i have and i need a user to enter there name and the binary value will come out for that asci value.. i did both codes separatelly but cant combine.. any help ?
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
void binary(int);
int main()
{
string name = "";
cout<< "Please enter your name: ";
cin >> name;
for ( int i=0; i<(int)Name.size(); i++ )
{
cout<< '\n' << (int)name[i] <<" ";
}
cout<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
void binary(int number) {
int remainder;
if(number <= 1) {
cout << number;
return;
}
remainder = number%2;
binary(number >> 1);
cout << remainder;
-