wrong code

Pages: 12
closed account (9SvpX9L8)
thanks dionisis!!

but , when im running ur code its a bit missunderstood.

i want that the user will press the charecters and not letters (such C instead of 2).
if the user will press C he will have option to make an account, and if press L he can enter an existing account . with password and all of this.
when he type a password he will chack if the letters are the same if thay r he will continue.

can i speak with u in the private ?
send me msg plz!
my brain hurts
closed account (9SvpX9L8)
why is that man ?
can u help me?
can i speak with u in the private ?

love is in the air, in every sight and every sound~~~
ok instead of using the switch on integers you can use a switch on chars simply do;;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
switch (input)
{
   case 'C': 
         makeAccount();
         break;

   case 'L':
         enterAccount();
         break;
   
   default:
         // this is an invalid option to get here...
         cout << "Error you must choose a valid option." << endl;
         break;
}


I would also make an option to quit in the main menu.
Loop the main menu as the supplied example already listed but change it around to suit your needs.
Last edited on
snoopy the tiger wrote:
>umm the codr you have written dont work
>i put iostream etc....
>
>
>you have any idea how do i write my project code?
>


The code works perfectly fine, It's the person who is implementing it that has the problem. Ask me a specific question. I know how to do your assignment, but I'm not going to do it for you unless you pay me or something. So if you would like to attempt it then ask a question and I will try to help you understand.
|

-----------------------------

Snoopy, the code won't work for you because I simply posted an example for it to work you would need the 'input' to be the variable char you are reading in. and the functions makeAccount(); enterAccount() would need to be implemented in your code.
Last edited on
Here's your code compiled and working, however it's a piece of crap no offense, you really need to start back at the beginning and work on basics. Please don't PM me anymore any questions can be posted so everybody can have a chance at answering them.
To start at the begining i suggest making "Hello World" app, then move on to some math functions if you can do math, then move on to strings and string manipulation and by that I mean make use of substring, strcpy and stuff, and then move onto OOP principles, and then arrays, then file reading/writing & exception handling, by this stage you should know how to proceed so you don't need me to instruct you.

Nobody is going to hold your hand through this, you need to learn how to teach yourself programming using the resources available (text books and this website documentation) teachers rarely teach anything, at best they say "do this work" then it is up to you to learn the work and do it.

http://cplusplus.com/doc/tutorial/

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
51
52
53
54
55
56
/* search_engine.cpp */

#include <iostream>
#include <string>
using namespace std;



int main ()
{
   int choice;
   string name, password, question, answer;

   cout << "Hello Guest \n";
   cout << "What would you like to do: \n";
   cout << "1. Log In?" << endl << "2. Search"
      << endl << "3. Stay" << endl;
   cin >> choice;

   switch (choice)
   {
      case 1:
         cout <<" [L]og in for an existing account. \n";

         cout << "User Name";
         getline (cin,name);
         cout <<" Password";
         cin >> password;
         cout <<"Welcome Back " << name;
         cout <<" Press [H]istory for see your search history";
         break;
      case 2:
         cout <<" [S]ign in. \n";
         cout <<"\t Welcome for Search Engine ! \n";
         cout <<"User Name: \n";
         getline (cin,name);

         cout <<"Password (6 numbers max);  \n";
         cin >> password;

         cout <<"Re-type your password: ";
         cin >> password;

         cout <<"Question for restore your password: \n";
         cin >> question;

         cout <<"Answer: \n";
         cin >> answer ;

         break;
      case 3:
         cout <<"Stay [G]uest. \n";
         break;
   }
}
Last edited on
Why, why, why!? Why did you do it for him? Gah; he doesn't learn if you just fix all his problems for him...

I gotta agree with gcampton. It doesn't look like you understand the syntax at all. I would recommend starting again from the tutorial, too.
I didn't do it for him, like I said it's a peice of shit.... that code does nothing I simply made it so it would compile.
@gcampton
I suppose, it does nothing useful. It won't even enter the switch, will it? IIRC cin won't convert the number given (which is a character); into an actual number, so you'll have to minus '0' from the answer. The quotes are important.

@snoopy the tiger
I will add, and it will sound harsh, that programming isn't for everyone. Maybe it isn't for you...
choice is an int so it will enter the switch, but the switch does nothing but store some variables then exit the program. It doesn't compare name/password with something stored on anything like an encrypted file.

personally I think he is just getting ahead of himself, there's no way he could create search_engine.cpp at this current level. Needs to go back to basics, while programming isn't for everyone I think it depends how badly you want it as well. It took me twice as long as anyone in my class to pickup yet I persisted and persisted because I knew it was what I wanted to do.
I still find some concepts are hard to grasp unless I fully research them. But I do and it works.
whew, someone to take the heat off of me ;)
@gcampton,
I thought cin didn't do any type-checking? Also, ints can store [tt]char[tt]s; because a char is an int. They're just a single byte wide (unless you use a wide char, but I don't know what the difference is). In C they used to use ints for storing the result of getchar() (getchar() returns int) and such. I think char was only used for arrays (i.e. C strings).

Oh well.
Hmm, I remember reading somewhere you shouldn't use both cin and getline in a program. Am I wrong in this?
IIRC cin won't convert the number given (which is a character); into an actual number, so you'll have to minus '0' from the answer.
I thought cin didn't do any type-checking?

operator>>() has an overload (among other overloads) for int:
std::istream &operator>>(std::istream &,int &);
It reads characters from the stream until it finds a non-whitespace, then it reads some more until it finds a non-digit. If no digits were read, it returns something (I'm not sure what, but calling operator!() on it returns true); otherwise it takes these digits and converts them to an int, which is assigned to the second parameter.
Last edited on
Oh ok...
Topic archived. No new replies allowed.
Pages: 12