Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,835 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,761 people online right now. Registration is fast and FREE... Join Now!




Arrays, strings and substrings

 
Reply to this topicStart new topic

Arrays, strings and substrings, I need help figuring out what I am doing wrong here.

codecutie
30 Sep, 2008 - 11:28 AM
Post #1

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 19


My Contributions
There are 3 parts to this program, the first is to enter 5 numbers and then output them backwards...that works fine. Second step im having a problem on, I need to be able to enter 5 words and after entering all five words the 1st and 3rd letter of each word is suppposed to out put. The next part is working for the most part but for some reason I cannot get the numbers from the inData file to output to outData backwards like its supposed to be. Any body have an idea where I can get information to fix this? Its due today at 5pm Mountain time. And its currently 1pm Mountain time.


CODE
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()

{

int list[5];
int num;
int counter;
char words;
int j;
string str[6];
ifstream inData;
ofstream outData;

cout << "Please enter FIVE numbers :";

num = 5;

for (counter = 0; counter < 5; counter++)
{
cin >> list[counter];
num = list[counter];
}

cout << endl;

for (counter = 4; counter >=0; counter--)
{
cout << list[counter] << " ";
}

cout << endl;

cout << "Enter five words: \n";

for (counter = 0; counter < 5; counter++)
{
j=counter + 1;
cout << "Word #" << j;
cin >> str[counter];
}

str[5] = "end_of_array";

cout << " ";

for (counter = 0; counter <= 5; counter++)
{
j=counter + 1;
cout << "Word #" << j << str[counter] << "\n";
}

inData.open("numbers.txt");
outData.open("output.txt");

for (counter = 4; counter >=0; counter--)
{
inData >> list[counter];
outData << "number: " << list[counter] << endl;
}

inData.close();
outData.close();

cout << endl;

  

return 0;

}

User is offlineProfile CardPM
+Quote Post

AmitTheInfinity
RE: Arrays, Strings And Substrings
30 Sep, 2008 - 10:09 PM
Post #2

C Surfing ∞
Group Icon

Joined: 25 Jan, 2007
Posts: 1,026



Thanked: 35 times
Dream Kudos: 125
My Contributions
CODE

for (counter = 0; counter <= 5; counter++)
{
j=counter + 1;
cout << "Word #" << j << ": char 1:" << str[counter].at[1] << " char 3:"<< str[counter].at[3] <<"\n";
}


and

CODE

inData.open("numbers.txt");
outData.open("output.txt");

for (counter = 4; counter >=0; counter--)
{
inData >> list[counter];
}
for (counter = 0; counter <=4; counter++)
{
outData << "number: " << list[counter] << endl;
}
inData.close();
outData.close();


I hope this will help you. smile.gif
User is offlineProfile CardPM
+Quote Post

codecutie
RE: Arrays, Strings And Substrings
6 Oct, 2008 - 01:39 PM
Post #3

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 19


My Contributions
QUOTE(AmitTheInfinity @ 30 Sep, 2008 - 11:09 PM) *

CODE

for (counter = 0; counter <= 5; counter++)
{
j=counter + 1;
cout << "Word #" << j << ": char 1:" << str[counter].at[1] << " char 3:"<< str[counter].at[3] <<"\n";
}


and

CODE

inData.open("numbers.txt");
outData.open("output.txt");

for (counter = 4; counter >=0; counter--)
{
inData >> list[counter];
}
for (counter = 0; counter <=4; counter++)
{
outData << "number: " << list[counter] << endl;
}
inData.close();
outData.close();


I hope this will help you. smile.gif



Thanks smile.gif now I need to redo my final project anime2.gif I lost all the information off of my lap top and now I am starting from scratch and its already one day late. sad.gif
User is offlineProfile CardPM
+Quote Post

codecutie
RE: Arrays, Strings And Substrings
7 Oct, 2008 - 12:14 PM
Post #4

New D.I.C Head
*

Joined: 15 Sep, 2008
Posts: 19


My Contributions
CODE
//Week 9 Final project:
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
    //declare variables
    char menuChoice;
    int userInputA;
    int product;
    int qty;
    double price;
    ifstream inFile;
    ofstream outFile;

    do
    {

    cout << "What would you like to do today?" << endl;//Create menu for ordering system:
    cout << "A-Order new items?" << endl;//menu choice to order item (A)
    cout << "B-Check new sale items?" << endl;//menu choice to check and order (B)
    cout << "C-Exit ordering system." << endl;//menu choice to exit ordering system (C)
    cout << "Please enter your choice: ";// prompt for entering menu choice
    cin >> menuChoice;//user input menu choice

    cout << "\n";//New line

    switch (menuChoice)//choice A: Allow switch in case for user input to either “A” or “a”
    {
        case 'A':
        case 'a':
            // list of 5 items for user to chose from
            cout << "Please chose which item you would like to order:" << endl;
            cout << "0-Body Dew Spray-11.00." << endl;//item number 1 body spray
            cout << "1-Cherry Body Butter-9.50." << endl;//item number 2 body lotion
            cout << "2-Slumber Bubbles-11.50." << endl;//item number 3 bubble bath
            cout << "3-Scented Massage Oil Candle-15.00." << endl;//item number 4 candle
            cout << "4-Sensura Massage Oil-14.00." << endl;//item number 5 massage oil

            cin >> product; //user input item number

//array goes here
//if item number 0 price = 11.00
//if item number 1 price = 9.50
//if item number 2 price = 11.50
//if item number 3 price = 15.00
//if item number 4 price = 14.00

//once item number is selected price is shown prompt user for quantity
//once quantity chosen show total
//then show menu for next selection

// once all items chosen add all prices together for total
// generate order number to be cast from input file i.e 001, 002, 003, 004, etc
//order number and total sent to output file

break;
//choice b:
        case 'B':
        case 'b':

            cout << "Current Sale Items are" << endl;
            cout << "Cherry Body Butter 11.50 to 9.50" << endl;
            cout << "Body Dew Spray 12.50 to 11.00" << endl;

            


//prompt user to enter order number
//prompt user to enter date ordered

//show order number
//show date + 14days delivery time(your order will arrive --------)
        break;

//choice c:
        case 'C':
        case 'c':

            cout << "Thank you for your order, have a nice day!!!" << endl; // nice little exit message
            exit (0);


             default: // this is in case the user enters an option other then those given in which case they will get an error
                        // message and will be prompted to make another choice

                   if (menuChoice != 'a' || menuChoice != 'A' || menuChoice != 'b' || menuChoice != 'B' || menuChoice != 'c' || menuChoice != 'C')
                  

                   cout << "That is an invalid selection, please try again." << endl;
                  

                   break;
    }

                      

   }while (menuChoice != 'C' || menuChoice != 'c');  


    return 0;



//exit ordering system

}



can somone help me here, I am not sure about the array and string values here. I am trying to get this done quickly as its due in 3 hours. And is there a way that I can print indata information to the console for the purposes of maybe changing option b to a wish list?
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/3/08 03:59PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month