Why "iscntrl" returns 2? - c++

I want to know why, when I print the instruction iscntrl, the return value is always 2?
I also want to know why the result of the isalpha statement is 1024.
For example:
#include <iostream>
using namespace std;
int main()
{
char lettera = 'c';
char numero = '1';
isalpha(lettera)? cout << lettera << " è un carattere!" : cout << lettera << " non è un carattere!";
isalpha(numero)? cout << numero << " è un carattere!" : cout << numero << " non è un carattere!";
cout << endl << isalpha(lettera) << endl; //print 1024
cout << isalpha(numero) << endl; //print 0
cout << iscntrl(numero) << endl; //print 0
cout << iscntrl(1) << endl; //print 2
}

The iscntrl() function return value:
A value different from zero (i.e., true) if indeed c is an alphabetic
letter. Zero (i.e., false) otherwise.
The isalpha() function return value:
A value different from zero (i.e., true) if indeed c is a control
character. Zero (i.e., false) otherwise.
So, it returns non-zero value (not 1) when the condition is true. So that's intentional.
Also, a tiny note:
isalpha(lettera)? cout << lettera << " è un carattere!" : cout << lettera << " non è un carattere!";
isalpha(numero)? cout << numero << " è un carattere!" : cout << numero << " non è un carattere!";
Those two statements are very similar, so you should make a function:
inline void printmsg(char ch)
{
std::cout << ch << (isalpha(ch) ? "" : " non") << " è un carattere!";
}
and call it:
printmsg(lettera);
printmsg(numero);

Related

How do I limit the amount of digits accepted from the user?

I currently have this and I can't seem to make my else work so the whole program doesn't limit the input successfully. (Sorry for my English I speak French).
cout << "Veuillez entrer votre nombre de 6 chiffres : ";
cin >> val;
if (val < 100000);
{
cout << "Erreur! Veuillez recommencez avec un nombre a 6 chiffres. " << endl << endl;
return main();
}
if (val > 999999);
{
cout << "Erreur! Veuillez recommencez avec un nombre a 6 chiffres. " << endl << endl;
return main();
}
else
if
{
nb1 = val / 100000 % 10;
cout << nb1;
}
Firstly, a semicolon between the ) and { of an if statement creates an empty if statement body, followed by an unconditional block, which is not what you want.
To check if a number has more than a certain number of digits, try comparing against negative 999999 instead.
The code should be made shorter by using logical operators instead of 2 separate if statements.
Lastly, you should not recurse into main(). Use goto instead.
Corrected Code:
retry:
cout << "Veuillez entrer votre nombre de 6 chiffres : ";
cin >> val;
if (val < -999999 || val > 999999) // Note the ; has been removed
{
cout << "Erreur! Veuillez recommencez avec un nombre a 6 chiffres. " << endl << endl;
goto retry;
}
nb1 = val / 100000 % 10;
cout << nb1;
Alternatively, you could use the abs() function (use #include <cstdlib>):
if (abs(val) > 999999)
{
cout << "Erreur! Veuillez recommencez avec un nombre a 6 chiffres. " << endl << endl;
goto retry:
}
nb1 = val / 100000 % 10;
cout << nb1;

How do I print an individual value from an array within text?

I'm trying to pull individual values from an array and put them into text, but keep running into errors with syntax.
#include <iostream>
#include <ostream>
using namespace std;
// PV, PM, FUE, RAP, PRE, SAB, ESP
int luch_bas [7] = {6,3,5,3,2,1,2};
int main ()
{ cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... " luch_bas[0] "\n";
cout << "Puntos de Magia (PM)..." luch_bas[1] "\n";
cout << "Fuerza (FUE) ..." luch_bas[2] "\n";
cout << "Rapidez (RAP) ..." luch_bas[3] "\n";
cout << "Precisión (PRE) ..." luch_bas[4] "\n";
cout << "Sabiduría (SAB) ..." luch_bas[5] "\n";
cout << "Espíritu (ESP) ..." luch_bas[6] "\n";
}
The error log I keep getting is "expected ';' before 'luch_bas'", but I'm not exactly sure where the missing ; is supposed to go? I'm sure there's a much better way to code this; I am still learning.
try this
int main ()
{ cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... \t" << luch_bas[0]<< "\n";
...
}
The error log I keep getting is "expected ';' before 'luch_bas'", but I'm not exactly sure where the missing ; is supposed to go?
You don't wan't to put a ; as the error message suggests. You want to chain the output operator calls respectively.
The std::ostream& operator<<(std::ostream& os, Type t) returns a std::ostream& reference as you can see.
The correct way is to chain the operator<<() calls:
cout << "Puntos de Vida (PV)... " << luch_bas[0] << "\n";
// ^^ ^^
It should be:
cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... " << luch_bas[0] << endl;
cout << "Puntos de Magia (PM)..." << luch_bas[1] << endl;
cout << "Fuerza (FUE) ..." << luch_bas[2] << endl;
cout << "Rapidez (RAP) ..." << luch_bas[3] << endl;
cout << "Precisión (PRE) ..." << luch_bas[4] << endl;
cout << "Sabiduría (SAB) ..." << luch_bas[5] << endl;
cout << "Espíritu (ESP) ..." << luch_bas[6] << endl;
use more "streaming" operators
#include <iostream>
#include <ostream>
using namespace std;
// PV, PM, FUE, RAP, PRE, SAB, ESP
int luch_bas [7] = {6,3,5,3,2,1,2};
int main ()
{ cout << "Tiene los atributos siguientes: \n";
cout << "Puntos de Vida (PV)... " << luch_bas[0] << "\n";
cout << "Puntos de Magia (PM)..." << luch_bas[1] << "\n";
cout << "Fuerza (FUE) ..." << luch_bas[2] << "\n";
cout << "Rapidez (RAP) ..." << luch_bas[3] << "\n";
cout << "Precisión (PRE) ..." << luch_bas[4] << "\n";
cout << "Sabiduría (SAB) ..." << luch_bas[5] << "\n";
cout << "Espíritu (ESP) ..." << luch_bas[6] << "\n";
}

else if expected expression c++ / Xcode

I have seen this problem around the forum but I have not been able to fix this issue. After all "else if" Xcode can't compile, it tells me that it is a "parse issue" and that requieres an "expected expression".
I know that it is a beginner's question but I truly want to understand what is wrong with my code, why it keeps telling me expected expression after each esle if...
if (TypeStrat == 1)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K,T,r,v) + BSPrixPut(S,K,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K,T,r,v) + BSDeltaPut(S,K,T,r,v)) << endl;
cout << "Vega " << (2*BSVega(S,K,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K,T,r,v) + BSRhoPut(S,K,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K,T,r,v)/365.0) + (BSThetaPut(S,K,T,r,v)/365.0)
<< "journalier" << endl;
else if (TypeStrat == 2)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) + BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) + BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) + BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) + BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) + (BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 3)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du short Call ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) - BSPrixCall(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) - BSDeltaCall(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) - BSRhoCall(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) - (BSThetaCall(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 4)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du short Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - (BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 5)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Call ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) - 2*BSPrixCall(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) - 2*BSDeltaCall(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) - 2*BSRhoCall(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) - 2*(BSThetaCall(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 6)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - 2*BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - 2*BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - 2*BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - 2*(BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
}
An else if requires a preceding if statement. The block of if statement that precedes your first else if is not closed, i.e. an ending curly brace } is missing. Also, there is an extra } in the end.
Missing curly brace:
if (TypeStrat == 1)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K,T,r,v) + BSPrixPut(S,K,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K,T,r,v) + BSDeltaPut(S,K,T,r,v)) << endl;
cout << "Vega " << (2*BSVega(S,K,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K,T,r,v) + BSRhoPut(S,K,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K,T,r,v)/365.0) + (BSThetaPut(S,K,T,r,v)/365.0)
<< "journalier" << endl;
// } <-- Insert ending curly brace here
else if (TypeStrat == 2)
Extra curly brace:
else if (TypeStrat == 6)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - 2*BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - 2*BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - 2*BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - 2*(BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
} // <-- Remove this extra curly brace
Looks like have a } in the wrong place. Is the following what you intended. Removed } from end and added before else if (TypeStrat == 2)
if (TypeStrat == 1)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K,T,r,v) + BSPrixPut(S,K,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K,T,r,v) + BSDeltaPut(S,K,T,r,v)) << endl;
cout << "Vega " << (2*BSVega(S,K,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K,T,r,v) + BSRhoPut(S,K,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K,T,r,v)/365.0) + (BSThetaPut(S,K,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 2)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) + BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) + BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) + BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) + BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) + (BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 3)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du short Call ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) - BSPrixCall(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) - BSDeltaCall(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) - BSRhoCall(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) - (BSThetaCall(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 4)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice du short Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - (BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 5)
{
cout << "Quel est le prix d'exercice du long Call ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Call ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixCall(S,K1,T,r,v) - 2*BSPrixCall(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaCall(S,K1,T,r,v) - 2*BSDeltaCall(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoCall(S,K1,T,r,v) - 2*BSRhoCall(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaCall(S,K1,T,r,v)/365.0) - 2*(BSThetaCall(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}
else if (TypeStrat == 6)
{
cout << "Quel est le prix d'exercice du long Put ?" << endl;
cin >> K1;
cout << "Quel est le prix d'exercice des deux short Put ?" << endl;
cin >> K2;
cout << "Prix de la stratégie " << (BSPrixPut(S,K1,T,r,v) - 2*BSPrixPut(S,K2,T,r,v)) << endl;
cout << "Delta " << (BSDeltaPut(S,K1,T,r,v) - 2*BSDeltaPut(S,K2,T,r,v)) << endl;
cout << "Vega " << (BSVega(S,K1,T,r,v) - 2*BSVega(S,K2,T,r,v)) << endl;
cout << "Rho " << (BSRhoPut(S,K1,T,r,v) - 2*BSRhoPut(S,K2,T,r,v)) << endl;
cout << "Theta " << (BSThetaPut(S,K1,T,r,v)/365.0) - 2*(BSThetaPut(S,K2,T,r,v)/365.0)
<< "journalier" << endl;
}

Caesar Crypher/Decypher Program. C++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I'm working on a school project, my project is a Cypher and Decypher program that works with Caesar Algorithm.
My program has to have the following characteristics:
The program must give the user the option to initiate again. (Done.)
If the user inputs something wrong, the program must ask the user to imput again. (Done with a bug.)
The user can only input letters and - por spaces. (I only need to add the space thing.)
The letter must be moved 5 places (ie. A = F) (Done.)
The program must consider capital letters. (Done.)
Each time you input a letter the screen must clear. (Done.)
At the end of the program you must be able to see the encrypted or decrypted text. (Needs to finish.)
What I need to know is how to make the program show me the encrypted text, counting all the inputs I have made so far while the program has been running.
And an extra thing is how can I input a whole text sentence and apply the Caesar Encryption, obviously I'd have to change almost all my code but I'd like how to do it.
This is the code I have so far, sorry if the sentences are in Spanish but I am living in Mexico for the moment and my classes are in Spanish. If you need me to translate the text I can gladly do it for you.
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main(int, char**) {
// Variables.
char l;
int x = 0;
char y = x + l;
bool volverainiciar;
volverainiciar = 1;
while (volverainiciar == 1) {
cout << "Favor de introducir la letra del mensaje que desea codificar."
<< endl;
cin >> l;
cout << " " << endl;
cout << " " << endl;
if ((l >= 'a' && l <= 'u') || (l >= 'A' && l <= 'U')) {
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra " << l << " tiene un codigo ASCII de: " << x + l
<< endl;
y = (l + 5);
cout << "La letra " << l << " encriptado tiene un valor de: " << y
<< endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver a "
"iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
} else if ((l >= 'v' && l <= 'z') || (l >= 'V' && l <= 'Z')) {
switch (l) {
case 'v':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: a" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'w':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: b" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'x':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: c" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'y':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: d" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'z':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: e" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'V':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: A" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'W':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: B" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'X':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: C" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'Y':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: D" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
case 'Z':
cout << "El mensaje a codificar es: " << l;
cout << " " << endl;
cout << " " << endl;
cout << "La letra u tiene un codigo ASCII de: " << x + l
<< endl;
cout << "La letra " << l
<< " encriptado tiene un valor de: E" << endl;
cout << " " << endl;
cout << " " << endl;
cout << "Se limpiara la pantalla..." << endl;
system("pause");
system("cls");
cout << " Desea volver a iniciar?" << endl;
cout << " " << endl;
cout << " Para volver a iniciar (1) , para no volver "
"a iniciar (0)" << endl;
cout << " " << endl;
cout << "Volver a iniciar: ";
cin >> volverainiciar;
cout << " " << endl;
cout << " " << endl;
break;
}
} else {
cout << "Ese simbolo no es valido, favor de introducir uno valido."
<< endl;
cin >> l;
cout << " " << endl;
cout << " " << endl;
continue;
}
}
cout << "Gracias por usar el encriptador/desencriptador." << endl;
exit;
return 0;
}
If you have any suggestions I'll gladly read them too :)
And sorry for any misspellings my english is not perfect because almost my whole life I've been living here...
I hate to trash your really long program, but it was annoying.
Try this:
// Given the input character is in x.
if (std::isalpha(x))
{
if (std::islower(x))
{
y = (x - 'a'); // Convert to a number.
y = y + 5; // Left shift by 5
y = y % 26; // Modulo arithmetic for all letters in alphabet
y = y + 'a'; // Convert back to character.
}
else
{
y = (x - 'A'); // Convert to a number.
y = y + 5; // Left shift by 5
y = y % 26; // Modulo arithmetic for all letters in alphabet
y = y + 'A'; // Convert back to character.
}
}
One of my pet peeves is duplicate code. Although there is duplicate code above, I've reduced the amount of duplication in your code. Feel free to add all your cout statements in the code above.
By the way, you can "block write" your data to cout, if the data doesn't use variables.
Example:
static const char answer_text[] =
"\n"
"\n"
"La letra u tiene un codigo ASCII de: ";
//...
cout.write(answer_text, sizeof(answer_text) - 1);
This will allow you to use the cout.write statement everywhere you need to use the same text. Less typing, less lines, less probability of injecting a defect.

How to call a stored procedure in Visual Studio 2012

So I have this program and I need to execute a stored procedure. But this gives me an error, "Invalid SQL statement". Already tried with begin proceudre() end. Same error. Help?
//Eliminar um docente de uma Edicao
void BDados::eliminarDocenteUnidade(EdicaoDisciplina edicao, string docente)
{
try
{
list <int> ed = separarEdicao(edicao.getEdicao());
stringstream comando;
comando << "execute p_eliminarDocenteUnidade('" << edicao.getSigla() << "'," << ed.front() << "," << ed.back() << ",'" << docente << "')";
cout << comando.str() << endl;
instrucao = ligacao->createStatement(comando.str());
instrucao->execute();
cout << "Docente eliminado com sucesso." << endl;
}catch(SQLException erro)
{
cout << erro.getMessage() << endl;
return;
}
}