Like Tree1Likes

Homework due tonight! help please!!

This is a discussion on Homework due tonight! help please!! within the C++ Programming forums, part of the General Programming Boards category; oh, wait, its changed now...

  1. #31
    Registered User
    Join Date
    Apr 2005
    Posts
    23
    oh, wait, its changed now

  2. #32
    Registered User
    Join Date
    Apr 2005
    Posts
    23

    Question

    so, should key be a string or a char? should i have it declared as "char key" or "string key"?

  3. #33
    Registered User
    Join Date
    May 2003
    Posts
    82
    A string and an array of chars have similiar functionality. Strings are preferred unless it's part of the program specification (some teachers have a fetish for char arrays (c-strings))

    Could you restate the problem?

  4. #34
    Registered User
    Join Date
    Apr 2005
    Posts
    23
    ok thank you, i have it as "string key[26];" is that correct?... ugh.. now my letters don't show on the output screen like they are supposed to.. *sigh* is it a lost cause? I hope not.

  5. #35
    Registered User
    Join Date
    Apr 2005
    Posts
    23
    annnndddd.... i also have an infinite loop after entering the characters and the input file

  6. #36
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Strings resize themselves automatically, so you don't need to declare how much memory they need or resize them yourself. However, since you know that you want to store 26 letters, you can use the reserve() function to set aside space for precisely 26 chars.

  7. #37
    Registered User
    Join Date
    Apr 2005
    Posts
    23
    this is my code now
    Code:
    
    #include <string> 
    using namespace std; 
    #include <fstream> 
    
    #include <iostream.h> 
    #include <stdlib.h> 
    
    int main() 
    { 
    ........ int i; 
    ........ string infilename; 
    ........ ifstream fin; 
    
    ........ string key[26]; 
    
    ........ for (i = 0;i < 26;i++) { 
    
    ............ cout << "Please enter your replacement for character" << key[i] << ": \n"; 
    ............ cin >> key[i]; 
    ........ } 
    ............ cout << "Please input a file (input)" << endl; 
    ............ cin >> infilename; 
    
    ........ if (fin.fail()){ 
    ................ cout << "Error - file opening failed" << endl; 
    ................ } 
    ........ while (!fin.eof()) { 
    ............ if (fin.eof()) 
    ............ break; 
    ............ for (int i = 0; i < 26; i++) { 
    ............ cout << "Your new message is: \n" << key[i] << endl; 
    ............ } 
    ........ } 
    ........ fin.close(); 
    
    ........ system("PAUSE"); 
    ........ return 0; 
    }
    Last edited by Andy717; 04-07-2005 at 01:00 PM.

  8. #38
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    This isn't looking good....make sure you understand the code people tell you to use before you use it. Period.

    I was helping another student out, but he had gotten so many chunks of code from other people that he had no idea how his program worked anymore and when he asked me for help the only thing I could tell him was to start over.

    Basically, not to get you depressed or anything, but if you don't understand it now, don't expect to understand it just by having people spoon feed it to you. You're going to need to put in the time and effort to learn the language on your own.

    -edit-
    And another thing, there's a lovely button called the edit button Use it so you don't have to keep making new posts.

  9. #39
    Registered User
    Join Date
    Apr 2005
    Posts
    23
    it wont let me post the whole code... ok, fixed

  10. #40
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    1) Where are you copying it from?
    2) How are you pasting it?
    3) What is the board saying about your code?

  11. #41
    Registered User
    Join Date
    Apr 2005
    Posts
    23
    well, my prof said he'll meet me (thank goodness) in about an hour and 10 mins... so, i hope he'll help me... well, he'll only help me with really specific things, but, at least it's help... and yeah, im trying to learn it, but... it's hard when i can't talk with anyone about it, or whatever... ehh.. oh well..
    Last edited by Andy717; 04-07-2005 at 01:15 PM.

  12. #42
    Registered User
    Join Date
    Apr 2005
    Posts
    23
    well, thanks everyone for your help... im out..

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 50 percent for this homework?
    By a.mlw.walker in forum C Programming
    Replies: 2
    Last Post: 03-22-2009, 05:15 PM
  2. please help..linked list homework assignment due tomorrow..
    By rocketman03 in forum C Programming
    Replies: 2
    Last Post: 11-23-2008, 05:32 PM
  3. Help Someone! First program/errors and its due tonight!
    By LittleLotte in forum C Programming
    Replies: 4
    Last Post: 02-02-2005, 08:21 AM
  4. Its Late...Due Tonight....Help Please
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 11-13-2001, 02:18 PM
  5. Homework
    By kermi3 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-03-2001, 03:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21