C++ Problems

Joined
Jul 16, 2011
Messages
3
Reaction score
0
Points
1
Your Mac's Specs
iMac: 21.5", 3.2GHz Intel i3 processor, 4GB RAM, 1 TB internal HD, and ATI Radeon HD 5670 graphics
I just finished my first C++ program at a camp not too far from where I live. It was made using Microsoft's Visual C++... something, may not be the full name. :\ Anyway, I tried using Xcode to build and run it, but I can't. Probably user's fault. :Blushing: Any suggestions? Thanks!

PS: I think it may be missing resource files or something like that.

Here's the header of the code, if that helps at all.

#include <string>
#include <iostream>
using namespace std;
 

chscag

Well-known member
Staff member
Admin
Joined
Jan 23, 2008
Messages
65,248
Reaction score
1,833
Points
113
Location
Keller, Texas
Your Mac's Specs
2017 27" iMac, 10.5" iPad Pro, iPhone 8, iPhone 11, iPhone 12 Mini, Numerous iPods, Monterey
Moved to correct forum. You'll likely get more replies in this forum which is dedicated to development and programming.
 
OP
N
Joined
Jul 16, 2011
Messages
3
Reaction score
0
Points
1
Your Mac's Specs
iMac: 21.5", 3.2GHz Intel i3 processor, 4GB RAM, 1 TB internal HD, and ATI Radeon HD 5670 graphics
Moved to correct forum. You'll likely get more replies in this forum which is dedicated to development and programming.
Thanks!
 

rman


Retired Staff
Joined
Dec 24, 2002
Messages
12,637
Reaction score
168
Points
63
Location
Los Angeles, California
Your Mac's Specs
14in MacBook Pro M1 Max 32GB 2TB
To get a better results, it would be helpful to give the error message you are getting and a copy of the program you are trying to compile.
 
OP
N
Joined
Jul 16, 2011
Messages
3
Reaction score
0
Points
1
Your Mac's Specs
iMac: 21.5", 3.2GHz Intel i3 processor, 4GB RAM, 1 TB internal HD, and ATI Radeon HD 5670 graphics
Ok, there is no error code, the option to build and run is light gray (un-selectable) and the code is:

// 07 July 2011
#include <string>
#include <iostream>
using namespace std;

// Encryption code
void enc(string& s, int shift[], int numshift){
for (unsigned i = 0; i < s.length(); ++i){
if (s >= 97 && s <= 122){
s -= 'a';
s = (s + shift[i%numshift] + 26) % 26;
s += 'a';
}
if (s >= 65 && s <= 90){
s -= 'A';
s = (s + shift[i%numshift] + 26) % 26;
s += 'A';
}
}
}
// Decryption code
void dec(string& s, int shift[], int numshift){
for (unsigned i = 0; i < s.length(); ++i){
if (s >= 97 && s <= 122){
s -= 'a';
s = (s - shift[i%numshift] + 26) % 26;
s += 'a';
}
if (s >= 65 && s <= 90){
s -= 'A';
s = (s - shift[i%numshift] + 26) % 26;
s += 'A';
}
}
}
int main(){
// Variables
int numshift;
char choice;
int* shift;
string input;
// Input/Output Code
do{
// prompts user to enter encryption or decryption choice
choice='?';
cout << "Encrypt (E) or Decrypt (D)?: ";
cin >> choice;
// Encrypt/decrypt selection error checking
if (choice!='d'&&choice!='D'&&choice!='e'&&choice!='E'&&choice!=' '){
do{
cout << "Please re-enter your selection: ";
cin >> choice;
}while(choice!='d'&&choice!='D'&&choice!='e'&&choice!='E'&&choice!=' ');
}
// User selects the number of shift values he/she wants
cout << "Enter the number of shift values. ";
cin >> numshift;
shift=new int [numshift];
// User enters shift values
for(int i=0; i<numshift; i++){
cout << "Input value of shift #" << i+1 << ": ";
cin >> shift;}
// Input/ output codes
while(choice==' ');{
switch(choice){
case 'e':
case 'E':
// Encryption input/output
cout << "Enter text to be encrypted: ";
cin.ignore(1);
getline(cin,input);
enc(input, shift, numshift);
cout << "Here is your encrypted text: " << input << endl << endl;
break;
case 'd':
case 'D':
// Decrytpion input/output
cout << "Enter text to be decrypted: ";
cin.ignore(1);
getline(cin,input);
dec(input, shift, numshift);
cout << "Here is your decrypted text: " << input << endl << endl;
break;
case ' ':
break;
}
}
// deletes array to prepare for next loop
delete[]shift;
}while(true);
}
 
Joined
Jul 23, 2011
Messages
2
Reaction score
0
Points
1
same problem!

i kinda have the same problem with c++ in XCODE... the thing is when i'm done with the coding part, i push build and everything works fine... but i cannot see the result!! how can i see the outcome of my C++ program in XCODE??
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top