Reputation: 25
So I'm writing a code that gives me the "opposite" letter on the ASCII table in c++. I'm running into the error
main.cpp:28:29: error: expected ‘,’ or ‘;’ before ‘{’ token
string letter_swap(ref_word){
Here is what I have so far:
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::noskipws;
string word;
string &ref_word = word;
string letter_swap(ref_word){
int diff;
cin >> ref_word;
num_word = static_cast<int>(ref_word);
if (65 <= num_word & num_word <= 90){
diff = 90 - num_word + 65;
return diff;
} else if (97 <= num_word & num_word <= 127){
diff = 90 - num_word + 65;
return diff;
} else{
return ref_word;
}
}
I really can't tell where I'm missing the ; Any help is greatly appreciated
Upvotes: 0
Views: 1268
Reputation: 9672
You haven't specified the argument type for ref_word.
string letter_swap(string& ref_word){
These look like they shouldn't be there:
string word;
string &ref_word = word;
You might also want to use && instead of &.
if (65 <= num_word && num_word <= 90)
You have not declared num_word as a variable, and you can't convert a numerical text value into a numeric value like this:
num_word = static_cast<int>(ref_word);
You probably want to be doing something along these lines:
size_t sz;
int num_word = std::stoi(ref_word, &sz);
Upvotes: 1