PDA

View Full Version : Simple password script... Need help!


Kankles
08-24-2009, 09:46 PM
This is the code I've implemented. Very basic.



#include <iostream>

using namespace std;

int main(){

char myArray[50];

cout << "What is the password? ";

cin.getline( myArray, 50, '\n');

if( !strcmp( myArray, "password")){

strcat( myArray, " is correct! Access granted!\n");

} else {

strcpy( myArray, "Invalid password!\n");

}

cout << myArray;

system("pause");

}



The error I am getting is:



Compiling: C:\Users\Chris\Documents\Scripts\Strings.c
C:\Users\Chris\Documents\Scripts\Strings.c:1:20: iostream: No such file or directory
C:\Users\Chris\Documents\Scripts\Strings.c:3: error: syntax error before "namespace"
C:\Users\Chris\Documents\Scripts\Strings.c:3: warning: data definition has no type or storage class
C:\Users\Chris\Documents\Scripts\Strings.c: In function `main':
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: `cout' undeclared (first use in this function)
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: (Each undeclared identifier is reported only once
C:\Users\Chris\Documents\Scripts\Strings.c:9: error: for each function it appears in.)
C:\Users\Chris\Documents\Scripts\Strings.c:11: error: `cin' undeclared (first use in this function)
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 1 warnings

another script i was having difficulty with was from the second tutorial..



#include <iostream>

using namespace std;

int main ()

char name[40]{

cout << "Hello! What is your name?\n";
cin >> name;
cout << "Welcome to my program " << name;

system("PAUSE");
return 0;

}

It returned the errors:



Compiling: C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c
C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c:6: error: expected init-declarator before "char"
C:\Users\Chris\Documents\Scripts\C++\Hello 2\second step to hello.c:6: error: expected `,' or `;' before "char"
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 0 warnings

Nordinwanabe
08-24-2009, 10:02 PM
umm

syntax error before "namespace"

that has something to do with a spelling mistake before the word namespace

so you might wanna check that out first.

umm also in the second one.

C++\Hello 2\second step to hello.c:6: error: expected `,' or `;' before "char"

you need to put on of those things before char to make this error go away.

Kankles
08-24-2009, 10:21 PM
The problem is, I've tried resolving it like that..


but that isnt how the code works.

Like, it is common sense to check those parameters but..

the code is right so it makes no sense for them to be saying that..

Brains
08-25-2009, 02:23 AM
#include <iostream>
using namespace std;
int main () {
char name[40];
cout << "Hello! What is your name?\n";
cin >> name;
cout << "Welcome to my program " << name << "\n";
system("PAUSE");
return 0;
}




If that doesn't work something is wrong with your compiler.

Nordinwanabe
08-25-2009, 02:30 AM
Hey I just realised in the secound one what is cout and cin shouldn't it be count and something else?

Try changing cout to count and check if one of the two errors go.

Brains
08-25-2009, 02:35 AM
Hey I just realised in the secound one what is cout and cin shouldn't it be count and something else?

Try changing cout to count and check if one of the two errors go.
LOL cout is an output to the cmd. Like in java you have System.error.println("texthere") in C++ it's: cout << "texthere"; cin is the input side of that. You can store user input into a variable using that.

Nordinwanabe
08-25-2009, 02:42 AM
LOL cout is an output to the cmd. Like in java you have System.error.println("texthere") in C++ it's: cout << "texthere"; cin is the input side of that. You can store user input into a variable using that.


I ok my bad idk a lot bout c++ but I know and understand algorithms.

Brains
08-25-2009, 02:50 AM
I just compiled and ran your first block of code and it works for me.
What IDE are you using?

travishuss
08-25-2009, 03:02 AM
what is this for???

Kankles
08-25-2009, 05:57 AM
I'm using Code Block.

And, I'm not sure why those errors are coming up..

I'm just learning a bit more C++ and refreshing my memory but this code wont work for me.

I did post the errors so if someone knows how to fix those errors.. :|

also, these are simple boring things that have to do with command prompt. (adding, subtracting, or entering random numbers and getting different outputs.. etc..



edit: the script you posted brains is the same thing except with an added space :P
I'll open the script in another program and try it.. but i'd still like feedback if possible

edit2:.. didnt compile with others either. something about iostream not being a directory or something..

Brains
08-25-2009, 07:37 AM
I use DevCpp, which is really simple to use and isn't in your face trying to tell you what to do next(which those things usually tell me the wrong thing anyways).
The code I posted fixed some of your bracket mismatches and some simple things.

If I was you I would reinstall your libraries and everything for C++, because obviously something is wrong with them.

Arsenal
08-25-2009, 09:05 AM
System Pause is a beast on your computer. Not that it slows a program or that down, it just has to call it every time. But I still use it. And I use Dev-CPP as well.

Kankles
08-25-2009, 04:30 PM
Yeah i tried the script with devcpp and with codeblocks and neither worked. that's why i posted here.

any idea on what i should uninstall so that i can reinstall the libraries? :P

Here is a new problem. I fixed the Hello script. :P




#include <iostream>

using namespace std;

int addNumbers( int a, int b){

return a+b;

}

int main(){

int a;
int b;

cout << "Enter a number: ";
cin >> a;

cout << "Enter another number: ";
cin >> b;

cout << "Sum of the two numbers is: " << addNumbers( a, b) << "\n";

system("pause");

return 0;

}

The errors are:



Compiling: C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c:1:20: iostream: No such file or directory
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c:3: error: syntax error before "namespace"
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c:3: warning: data definition has no type or storage class
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c: In function `main':
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c:16: error: `cout' undeclared (first use in this function)
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c:16: error: (Each undeclared identifier is reported only once
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c:16: error: for each function it appears in.)
C:\Users\Chris\Documents\Scripts\C++\Functions(inc )\Functions.c:17: error: `cin' undeclared (first use in this function)
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 1 warnings

Edgar
08-25-2009, 05:43 PM
Do not ****ing double post. :@

Nice, atleast you fixed it. :D

Kankles
08-26-2009, 06:38 AM
Do not ****ing double post. :@

Nice, atleast you fixed it. :D


whiny *****.

double posting is fine in every other rainbows forum i've entered.

aside from that, it's the content that matters. If i post once, and then post again on something entirely different and also wanting to UPDATE MY STATUS... i'll HAVE to double post, because rainbows editing does NOT "BUMP", or BRING UP MY POST.

so stfu.


stupidass forum noobs.