Problems with my imput

My program is working fine, but it is not giving me the out put that i need.

[#include <iostream>
#include <cmath>


int main()
{
using namespace std;

int codigo;
int respuesta;
int s,n;



cout <<"Entra tu codigo de cuatro dijitos.\n"<<endl;

do
{

cin >>codigo;

if (codigo > 7148)
cout <<"De donde sacaste ese nunmero?"<<endl;

else if (codigo < 7148)
cout <<"Trata de nuevo ese no era, bruto"<<endl;


else if(codigo = 7148)
do
{
cout <<"Sabes quien creo este programa ? S/N"<<endl; // S/N stands for yes or no.
cin >> respuesta;

if (respuesta == 's' || respuesta == 'S') // once i enter the 's' or 'n' it takes me to my else statemen and does not show the outputs that i want.

cout <<"jabla jabla."<<endl;


else if (respuesta == 'n' || respuesta == 'N')

cout <<"Yo se, que no lo sabes."<<endl;

else
cout <<"Por favor, presione 's' o una 's'."
<<"no importa si es mayuscula o no."<<endl;

while(respuesta !=s || respuesta !=n); // if i press another letter, it terminates my program instead of asking again
}

while (codigo !=7148);

cout <<"Sigue tratando"
<<"\n"<<endl;


system ("pause");

}

while (codigo != 7148);
return 0;

}



ohhh i don't know if it matters but i'm using visual c++ 2010 express

Last edited on
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.
Last edited on
sorry.

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>

using namespace 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;

else if (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;

  else if (respuesta == 'n' || respuesta == 'N')
     cout <<"Yo se, que no lo sabes."<<endl;

  else if(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


Instead, is that correct?
yes, hanst99.
thats exactly what i want.
so I gues I didnt help at all :D
Nevermind, I compiled sikacs code. Which btw doesn't do what you want.
(though its closer than your own version).
Last edited on
Actually sikac
your does work, the only thing is that if i input others numbers instead of the 7148
it doesn't let me try again, as i had in my code.

But thanks a lot hanst and sikac its all working now.
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).

What would be the easiest way to do this?
If that's frowned upon on this forum, please say so

It is. It just makes it hard to find appropitiate threads. if you have a new question, make a new thread.
Topic archived. No new replies allowed.