473,326 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Contact List pt. 2

Hunderpanzer
I've been working on that "contact list" on and off now, and now I'm really trying to get it complete.

I'm trying to reduce the clutter right now, and make it more readable. All the braces and if, else statements are getting pretty big, so I tried putting them in functions.

I declared it, called it and defined it properly ( I hope) but it doesn't seem to be working. The program Compiles fine, no errors or warnings. But when the time comes to call the function, it doesn't call for some reason.

Expand|Select|Wrap|Line Numbers
  1. string option_one(){
  2.  
  3.        string pass1, pass2;       
  4.        cout << "\n\n\t Enter your new password:.";
  5.        cin.ignore();
  6.        getline(cin, pass1);
  7.        cout << "\n\n\t Enter your new password once more (Verification Purposes):.";
  8.        cin.ignore();
  9.        getline(cin, pass2);
  10.             if (pass1 == pass2){
  11.                Realpass = pass1;    //Realpass is defined globally
  12.                cout << "\n\n Password has been changed successfully! ";
  13.                                }
  14.             if (pass1 != pass2){
  15.                cout << "\n\n The two passwords did not match :'[  ";
  16.                                 }
  17.         return 0;   
  18.                     }
  19.  
Can a function just be made of a bunch of ifs, else, couts and getlines ?

My guess is, that there's no such thing as a string function? I tried even using a void function, but I get the same results.


I also understand that this function is pointless since it doesn't actually store the new Realpass into a file, but I'll get that tackled sooner or later. Right now, I just want to get the menus set up correctly.

I apologize for the trouble.
Aug 17 '07 #1
6 1488
RRick
463 Expert 256MB
The compiler is not stopping the subroutine from being called. The contents of a method does not dictate whether it is called or not (even though it looks like that is happening).

Your problem probably lies with the logic of your code. This is where a debugger can help. That or surround the suspect area with lots of print statements. The logic is there, you just have to dig it out.
Aug 18 '07 #2
The compiler is not stopping the subroutine from being called. The contents of a method does not dictate whether it is called or not (even though it looks like that is happening).

Your problem probably lies with the logic of your code. This is where a debugger can help. That or surround the suspect area with lots of print statements. The logic is there, you just have to dig it out.

Bah, I'm sorry. I just don't know what's going wrong here.

I made a new program with a simple function with getlines and couts.
It did the same thing. I used cin.ignore( ) incase a newline was making act funny. .
I tried changing all class string types, to char* strings, and using atof(s) and atoi(s). . .

I tried using the debugger from my compiler but I dont seem to know how to get it to work properly.


Sorry, but I'm out of ideas.
Aug 18 '07 #3
ilikepython
844 Expert 512MB
Bah, I'm sorry. I just don't know what's going wrong here.

I made a new program with a simple function with getlines and couts.
It did the same thing. I used cin.ignore( ) incase a newline was making act funny. .
I tried changing all class string types, to char* strings, and using atof(s) and atoi(s). . .

I tried using the debugger from my compiler but I dont seem to know how to get it to work properly.


Sorry, but I'm out of ideas.
How are you calling the function? What makes you think the function isn't called? Also, in the code above you, i fyou return 0 you should declare it like this:
Expand|Select|Wrap|Line Numbers
  1. int option_one();
  2.  
Aug 19 '07 #4
How are you calling the function? What makes you think the function isn't called? Also, in the code above you, if you return 0 you should declare it like this:
Expand|Select|Wrap|Line Numbers
  1. int option_one();
  2.  

Well I think it's not being called because when I call the function by doing:

Expand|Select|Wrap|Line Numbers
  1.                             if (choice == 1){
  2.           cout << " it sHOULD work";
  3.                      string option_one();
  4.                                      }
  5.  
  6.          else{
  7.          cout <<" Pardon Me ? " << endl << endl;
  8.          goto Menu;                       
  9.               }                             
  10.  
When the program is run, I press 1, and it prints
it sHOULD work Pardon Me?

the function should have opened up some more options (see above)

Also, I've tried using
Expand|Select|Wrap|Line Numbers
  1. int option()
(and changed the corresponding call and prototype) but it does the exact same thing.

Just now I thought of an idea to test if it was being called by using

Expand|Select|Wrap|Line Numbers
  1. system("pause");
at the beginning of the function definition.
I get the same response. - it sHOULD work Pardon Me ?

Maybe I'm calling it wrong? My book doesn't explain returns and calling all that well.
It uses
Expand|Select|Wrap|Line Numbers
  1.  return 0;
throughout the book.
Aug 19 '07 #5
ilikepython
844 Expert 512MB
Well I think it's not being called because when I call the function by doing:

Expand|Select|Wrap|Line Numbers
  1.                             if (choice == 1){
  2.           cout << " it sHOULD work";
  3.                      string option_one();
  4.                                      }
  5.  
  6.          else{
  7.          cout <<" Pardon Me ? " << endl << endl;
  8.          goto Menu;                       
  9.               }                             
  10.  
When the program is run, I press 1, and it prints
it sHOULD work Pardon Me?

the function should have opened up some more options (see above)

Also, I've tried using
Expand|Select|Wrap|Line Numbers
  1. int option()
(and changed the corresponding call and prototype) but it does the exact same thing.

Just now I thought of an idea to test if it was being called by using

Expand|Select|Wrap|Line Numbers
  1. system("pause");
at the beginning of the function definition.
I get the same response. - it sHOULD work Pardon Me ?

Maybe I'm calling it wrong? My book doesn't explain returns and calling all that well.
It uses
Expand|Select|Wrap|Line Numbers
  1.  return 0;
throughout the book.
Yes, you are calling the function wrong. To call it just do:
Expand|Select|Wrap|Line Numbers
  1. option_one();
  2.  
The return type is only written when you are declaring the function. Remember:
Expand|Select|Wrap|Line Numbers
  1. int some_function(int paramint1, floar paramfloat1);
  2. 1         2                     3 
  3. 1 -- return type of function
  4. 2 -- name of function
  5. 3 -- parameter list
  6.  
By doing this:
Expand|Select|Wrap|Line Numbers
  1. string option_one();
  2.  
You are probably delcaring a string called option_one.

Also, the return type should be the type of value you are using after the return keyword. If you return 0, your function should be "int func();". If you return str and str is a string type, you function should be "string func();".
Aug 19 '07 #6
Yes, you are calling the function wrong. To call it just do:
Expand|Select|Wrap|Line Numbers
  1. option_one();
  2.  
The return type is only written when you are declaring the function. Remember:
Expand|Select|Wrap|Line Numbers
  1. int some_function(int paramint1, floar paramfloat1);
  2. 1         2                     3 
  3. 1 -- return type of function
  4. 2 -- name of function
  5. 3 -- parameter list
  6.  
By doing this:
Expand|Select|Wrap|Line Numbers
  1. string option_one();
  2.  
You are probably delcaring a string called option_one.

Also, the return type should be the type of value you are using after the return keyword. If you return 0, your function should be "int func();". If you return str and str is a string type, you function should be "string func();".


Wow I really appreciate your explanation of functions !

You were exactly correct. I just had to erase string from the function call !

All that time ! bah !


Thank you so much, things are starting to roll faster now.
Aug 19 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Jason | last post by:
I'm struggling with this email code and I'm not php freak since I'm starting to learn php stuff. Could use some help... It seems that I get too many parse errors all over and cannot figure went...
3
by: Brian Henry | last post by:
Does anyone know of a way to pull my contact lists out of exchange server and into a VB.net application? or even a public contact list? Thanks! This is something I need really bad, any help would...
1
by: kannan | last post by:
Hi, I am trying to loop through outlook contact address and display in messagebox. I have used following code: Outlook._Application olApp = new Outlook.ApplicationClass(); Outlook._NameSpace...
1
by: Robert J. Bonn | last post by:
I'm trying to set up a contact list in MS Access 97. I've looked through a reference book and the program's help screens, but the light bulb isn't quite coming on for me. If one of you could take...
1
by: rjbonn | last post by:
I'm setting up a contact list for a musician, who is about to release her first CD. She would like a contact list that can track the people she meets, who will be in various categories -- fans,...
0
by: Robert J. Bonn | last post by:
I am setting up a contact list for a musician, who is about to release her first CD. She would like a contact list that can track all the people she meets, who will be in various categories --...
0
by: =?Utf-8?B?ZGIgY2hhbGxlbmdlZA==?= | last post by:
I am realy challenged by MSN Live. I was quite happy with my former hotmail. The new forced-upon-me version has caused me nothing but headaches and lots of work. It consumes huge amounts of my time...
2
by: JayaseelanVaiyapuri | last post by:
Hi, I would like to add a menu item in Contact List menu of PocketPC using c#. in Contact list menu contains Edit, Send Contact, copy contact etc.. Now i want to add a new menu item like...
4
by: tokcy | last post by:
HI every one, i am using tooltip on click of link and i want like when that tooltip open then background window would be blure(). can anyone help me...
2
by: swethak | last post by:
hi, i have to get the gmail contact list using jsp code. For that purpose i have to use the Google data Api <%@ page import="com.xdatasystem.contactsimporter.*" %> <% // automatically...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.