1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Need Help Running a program in C++ for Ubuntu (Linux)

  1. Nov 28, 2014 #1
    1. The problem statement, all variables and given/known data
    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.
    -------------------------------------------------------------------------------------------------------------------------------------------


    2. Relevant 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();
    }



    3. 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();
    }
     
    Last edited by a moderator: Nov 30, 2014
  2. jcsd
  3. Nov 29, 2014 #2

    Borek

    User Avatar

    Staff: Mentor

    1. Use [code][/code] tags to format your code, at the moment it is completely unreadable, as all references to [i] were treated as italic tags.

    2. What have you tried, and what have happened? "I have a serious trouble" doesn't tell us anything about what kind of problems you are experiencing.
     
  4. Nov 30, 2014 #3
    Well I'm trying to run it in Ubuntu but it's not running as I would it to in C program. I'm trying to change the few things in C to run it in C++ but it's not working too well for me. Where do I use code/code tags? I don't understand that. Please help
     
  5. Nov 30, 2014 #4

    Borek

    User Avatar

    Staff: Mentor

    [code]int main()
    {
    return 0;
    }[/code]

    is displayed as

    Code (Text):
    int main()
    {
        return 0;
    }
    instead of unreadable

    int main()
    {
    return 0;
    }

    You have still failed to explain what you are doing and what kind of problems you see. There are zillions of things that can go wrong, and not knowing what actions you take and what messages you see means we are not able to help.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Need Help Running a program in C++ for Ubuntu (Linux)
  1. C program help needed (Replies: 3)

Loading...