Stringy Problem.. HELP!!

just started learning c++ using dev c++ from bloodshed.net.

My problem was learning strings. Wrote the script to allow me to put in a password and it would make changes to the string and print the string it made and end. I tried to put a Exit Y/N... sort of thing... and its gone haywire from then... the problem is it doesn't ask me for the password the second time...

#include <stdio.h>
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
char myArray[50];
char x = 'n';
while ( x == 'n')
{
cout << "Enter Password \n";
cin.getline( myArray, 50, '\n');
if( !strcmp( myArray, "Cheesecake")){
strcat( myArray, " is correct!! Access granted!! \n");
}else{
strcpy( myArray, "Invalid password!\n");
}
cout << myArray;
cout << "\n Exit? \n Y/N";
cin >> x;
}
system ("pause");
}



Enter Password
Cheesecake
Cheesecake is correct!! Access granted!!

Exit?
Y/Nn
Enter Password
Invalid password!

Exit?
Y/N
y
Press any key to continue . . .


Could anyone suggest me a better software to run C++. I normally use freeware but if you suggest a paid one do mention it.. :)
Last edited on
now even this isnt working !! D: Please help maybe i need a new Compiler...

#include <iostream>

using namespace std;
int main ()
{
int a;
cout << "How many loops do you want?";
cin >> a;

while (a)
{
cout << a << "\n";
--a;
}
return 0;
}
you need to read more books about programing.
In first program, problem can be because you don't clean cin. But I don't know about it myself, as never used it.
I am trying to figure out the problem with a book.. but i am kinda like *big book... aaaaaaaah!!!* though i did check some places in the book where the problem could be solved but it left me confused.. Btw what is a Clean Cin? (clean sin... XD)
You need to put 'cin.ignore()' before u are recieveng a input...so that every time loop runs, cin.ignore discards your previous input! you can read about it here:
http://www.cplusplus.com/reference/iostream/istream/ignore/

and ur second program seems to work fine!

and for compiler dont use turbo C++ as it ignore certain mistakes in your program...
use MS Visual 2010 or Code::Blocks!
To your second program, if you are using dev C++, the program will close as soon as it's finished. Try putting this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <conio.h>
using namespace std;
int main ()
{
int a;
cout << "How many loops do you want?";
cin >> a;

while (a)
{
cout << a << endl;
--a;
}
getch();
return 0;
}
Topic archived. No new replies allowed.