Current location: Hot Scripts Forums » Programming Languages » C/C++ » New programmer here... is this program correct?


New programmer here... is this program correct?

Reply
  #1 (permalink)  
Old 01-27-04, 05:18 PM
kml21panther kml21panther is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
New programmer here... is this program correct?

Hello, I am a new C++ programmer and I want to make sure that my code that I have written is correct and would like if you programmers could look over it for me. Thanks!
** edit: guess I should tell you what its suppost to do **
The program is suppost to take in your first, middle and last name.. and then display a username with the first letter of ur first and middle names then your full last name. The password is your first name initial and last name initial then the last 4 digits in ur social security number and then the middle 2 digits.
The program works, but would like to know if I went about doing this right.


Quote:
// Kevin LaMantia
// Assignment #1
// 1-24-04

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

void main() {
string firstmidlast, ssn;
int a, b, c, d, e, firstl, secondl, thirdl;
cout << "Welcome to SAGS, the Student Account Generation System" << endl << endl;
cout << "You can use this program to request a computing account." << endl << endl;
cout << "Please enter your name (First M Last): ";
getline(cin, firstmidlast);
cout << "Please enter your social security number (ddd-dd-dddd): ";
getline(cin, ssn);
a = firstmidlast.find(" ",0);
b = firstmidlast.find(" ",a + 1);
c = firstmidlast.size();
d = b + 1;
e = c - d;
firstl = a - (a-1);
secondl = b - a;
thirdl = e - (e-1);

// This displays the username and password
cout << endl << "Thank you." << endl;
cout << "Your account will become active within 24 hours." << endl;
cout << "The username will be: " << firstmidlast.substr(0, firstl);
cout << firstmidlast.substr(a + 1, secondl - 1) << firstmidlast.substr(d,e) << endl;
cout << "The password will be: " << firstmidlast.substr(0, firstl);
cout << firstmidlast.substr(d, thirdl) << ssn.substr(7,4) << ssn.substr(4,2) << endl;

}

Last edited by kml21panther; 01-27-04 at 05:21 PM.
Reply With Quote
  #2 (permalink)  
Old 01-28-04, 09:07 PM
hyjacked hyjacked is offline
Wannabe Coder
 
Join Date: Nov 2003
Location: New Brunswick, Canada
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Looks good, but a few things.

I would suggest changing your variables a through e to something more meaningfull. It makes it hard to follow the code with just letters.

Also maybe you should store the username and password in a string and just print out that string. if you are going to be doing anything with these(ie: storing them) then you need to do it anyways, so you might as well do it and it will clean up your cout's quite a bit.

good otherwise I'd say.
__________________
hyjacked
Reply With Quote
  #3 (permalink)  
Old 01-29-04, 11:49 AM
kml21panther kml21panther is offline
Newbie Coder
 
Join Date: Jan 2004
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by hyjacked
Looks good, but a few things.

I would suggest changing your variables a through e to something more meaningfull. It makes it hard to follow the code with just letters.

Also maybe you should store the username and password in a string and just print out that string. if you are going to be doing anything with these(ie: storing them) then you need to do it anyways, so you might as well do it and it will clean up your cout's quite a bit.

good otherwise I'd say.

Thanks, i took ur advice and put the username and passowrd into a string and i also made the letters a threw e more meaningful. Thanks for taking the time to look at my code, i appreciate it!

Kevin
Reply With Quote
  #4 (permalink)  
Old 01-30-04, 11:51 PM
hyjacked hyjacked is offline
Wannabe Coder
 
Join Date: Nov 2003
Location: New Brunswick, Canada
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
glad to have helped, that's what we are here for.

happy coding
__________________
hyjacked
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a good PHP programmer! edwin27 Job Offers & Assistance 8 02-25-04 12:45 PM
Looking to hire a programmer... jet blast General Advertisements 3 01-18-04 11:31 AM
Short Command Line Based Item Order Program digioz C/C++ 20 12-27-03 08:17 PM
Urgent! Looking for PHP programmer Mr_Fingers PHP 2 11-02-03 12:45 AM
Need Help writing a C program trac1_1999 Script Requests 1 09-07-03 06:13 PM


All times are GMT -5. The time now is 04:40 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.