We have [ code ] tags in this forum, please use them.
My program is working fine, but it is not giving me the out put that i need.
It's not working fine if it doesn't output what you want, and please tell us what you want it to output, we can't read your thoughts. And I can't deduct it from your source code either, cause you didn't write it in english.
1) when i ask user to input 's' or 'n', i want it to tell me the answer that i created for those options,
but instead it give me my else statement.
2) if i input another letter, it takes me to my else statement and it doesn't let me try to input
the right letter.
sorry, i don't know if i'm explaining myself correctly, it's because i'm learning English as well
thats why i post the code so someone could run it and see what i meant.
#include <iostream>
usingnamespace std;
int main()
{
int codigo;
char respuesta;
int s,n;
cout<<"Entra tu codigo de cuatro dijitos.\n"<<endl;
cin >>codigo;
if (codigo > 7148)
cout <<"De donde sacaste ese nunmero?"<<endl;
elseif (codigo < 7148)
cout <<"Trata de nuevo ese no era, bruto"<<endl;
if(codigo==7148)
{
cout <<"Sabes quien creo este programa ? S/N"<<endl;
cin >> respuesta;
if (respuesta == 's' || respuesta == 'S')
cout <<"jabla jabla."<<endl;
elseif (respuesta == 'n' || respuesta == 'N')
cout <<"Yo se, que no lo sabes."<<endl;
elseif(respuesta !='s' || respuesta !='n' || respuesta !='N' || respuesta !='S')
{
cout <<"Por favor, presione 's' o una 'n'. No importa si es mayuscula o no."<<endl;
cout <<"Sabes quien creo este programa ? S/N"<<endl;
cin >> respuesta;
}
}
cout <<"Sigue tratando"<<"\n"<<endl;
system ("pause");
}
next time please do try to improve your english before posting :))
So, if I understood this right, your program goes like this right now:
Entra tu codigo de cuatro dijitos.
7148
Sabes quien creo este programa ? S/N
s
Por favor, presione 's' o una 'n'. No importa si es mayuscula o no.
Sabes quien creo este programa ? S/N
Sigue tratando
And you want
Entra tu codigo de cuatro dijitos.
7148
Sabes quien creo este programa ? S/N
s
jabla jabla.
Sigue tratando
Another topic-hijack! (If that's frowned upon on this forum, please say so. I prefer using a solved topic than making one myself with a similar title)
I'm trying to read in a large file of data. Sadly, the people who released this data did a terrible job at formatting it, making it very hard to read. My default reader (a method I found referenced on this forum a few months back) already gives back a better result than I anticipated. However, I still need to handle strings of letters and numbers combined. There are two types:
1. From the string "CAPACITY : 100" I need to extract the "100". The number could be any size, so no guarantee that it's the final 3 characters. It is guaranteed to be the only numerical value in that string and the non-numerical part (here: "CAPACITY : " will be identical for each instance. If possible, the ability to read a similar string with non-identical text and two numbers on random locations in that string would be handy, but not required.
2. From the string " 1 82 76" I need to extract the second and third numbers. The amount of digits of each numbers can vary, but they will always be present (so at least one digit) and they'll always be separated by a space. They will always be integers (but if there's an easy way to make it extendable to other numerical types, that could be handy); they can be positive and negative (obviously shown by a minus sign in front of the number itself).