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

Click For Summary

Discussion Overview

The discussion revolves around a participant's attempt to convert a C program into C++ for execution on an Ubuntu (Linux) system. The focus is on troubleshooting issues related to code formatting and execution, as well as understanding the differences between the two programming languages in this context.

Discussion Character

  • Homework-related
  • Technical explanation
  • Debate/contested

Main Points Raised

  • A participant describes their struggle to run a C++ program that is based on an example from a C program, specifically for Ubuntu, and requests assistance.
  • The original C code includes functions and constructs that may not translate directly to C++, prompting questions about proper syntax and functionality.
  • Some participants suggest using code tags for better readability of the posted code, indicating that formatting issues are hindering understanding.
  • Another participant emphasizes the need for clearer descriptions of the specific problems encountered, noting that vague statements about "serious trouble" do not provide enough context for assistance.
  • There is a mention of the correct way to display code snippets in the forum to avoid formatting issues, highlighting the importance of clarity in communication.

Areas of Agreement / Disagreement

Participants generally agree on the need for clearer communication regarding the issues faced, but there is no consensus on the specific problems with the code or how to resolve them. Multiple competing views on the best practices for formatting and troubleshooting remain present.

Contextual Notes

The discussion reflects limitations in the participant's understanding of C++ syntax compared to C, as well as potential misunderstandings about forum etiquette regarding code formatting. Specific error messages or behaviors of the code are not detailed, leaving the discussion open-ended.

Who May Find This Useful

This discussion may be useful for individuals learning to transition from C to C++, particularly in a Linux environment, as well as those seeking guidance on effective communication in programming forums.

Cam Tay
Messages
2
Reaction score
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;

count << "Enter msg:";
cin >> p;
count << "\n";
count << "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;
}
}
count << "\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;
}
}
}
count<< "\n";
puts(d);
getch();
}
[/B]
 
Last edited by a moderator:
Physics news on Phys.org
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.
 
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
 
[code]int main()
{
return 0;
}[/code]

is displayed as

Code:
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 37 ·
2
Replies
37
Views
5K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 21 ·
Replies
21
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K