- #1
Cam Tay
- 2
- 0
Homework Statement
m working on a Engineering Project and I'm having serious trouble trying to run this program in C++. I'm following an example of the program from Program done in C but I'm trying to convert it into C++. I'm going to link the example I'm following and what I'm doing trying to run it in C++. I want this to be able to run in Ubuntu (Linux) based system not for MSDOS (Microsoft) based system. If at all possible, could someone help me try to have this program example run in Ubuntu (Linux Based System) instead of MSDOS (Microsoft Based System)? Please Help.
-------------------------------------------------------------------------------------------------------------------------------------------
Homework Equations
This is the example I'm trying to follow from a C program to change it into C++
void main()
{
char c[10]={0},p[10],d[10]={0};
int i,l,k;
clrscr();
printf("Enter msg:");
gets(p);
printf("\n");
printf("Enter keysize:");
scanf("%d",&k);
puts(p);
for(i=0;i<10;i++)
{
if(p>=65 && p<=96)
{
c=((p-65+k)%26)+65;
}
else if(p>=97 && p<=122)
{
c=((p-97+k)%26)+97;
}
}
printf("\n");
puts(c);
for(i=0;i<10;i++)
{
if(c>=65 && c<=96)
{
if((c-65-k)<0)
{
d=c-k+26;
}
else
{
d=((c-65-k)%26)+65;
}
}
else if(c>=97 && c<=122)
{
if((c-97-k)<0)
{
d=c-k+26;
}
else
{
d=((c-97-k)%26)+97;
}
}
}
printf("\n");
puts(d);
getch();
}[/B]
The Attempt at a Solution
This is my work example:
//hillciphering.cpp
//Deciphering a Message
//using Hill Ciphering
----------------------------------
#include <iostream>
#include <string>
using namespace std;
void main()
{
char c[10]={0},p[10],d[10]={0};
int i,l,k;
cout << "Enter msg:";
cin >> p;
cout << "\n";
cout << "Enter Matrix Keysize:";
display("%d","&k");
puts(p);
for(i=0;i<10;i++)
{
if(p>=65 && p<=96)
{
c=((p-65+k)%26)+65;
}
else if(p>=97 && p<=122)
{
c=((p-97+k)%26)+97;
}
}
cout << "\n";
puts(c);
for(i=0;i<10;i++)
{
if(c>=65 && c<=96)
{
if((c-65-k)<0)
{
d=c-k+26;
}
else
{
d=((c-65-k)%26)+65;
}
}
else if(c>=97 && c<=122)
{
if((c-97-k)<0)
{
d=c-k+26;
}
else
{
d=((c-97-k)%26)+97;
}
}
}
cout<< "\n";
puts(d);
getch();
}[/B]
Last edited by a moderator: