Hi guys hope ur are all well!

I have a program im trying to finish and its not going well. I am quite new to C++ and am not the greatest.

I have code that ill post, but the problem is when i run the program with the readfile(); function within the main method it will display the 2 menus. When readfile(); is active it does not run?? Pls accept my appoligies if the code is not wraped properly its the first time i have posted!!

Cheers Brendan

/*
 *
 * 
 *
 * 
 *
 **************************/
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <conio.h>
#include <string>
#include <windows.h>

using namespace std;

const int quit = 7;
const int MAX = 3;

struct tm *Sys_T = NULL;

//set up record structure
typedef struct
{ 
    char bean_type [20];
    int stock_amount;
    char purch_date [12];
}coffee;

typedef coffee coffee_list[MAX];
int coffeecount = 0;

int logon();
void readfile();
void writefile();
void managermenu();
void barristamenu();
void date();
void display(coffee_list);
void processorder(coffee_list& );
void addstock();

// details of the actual array of records
coffee_list cl;         


void main()
{   // code here
    date();
    int proceed;

    // display date and time

    proceed = logon();

    if ((proceed ==1) || (proceed == 2))
    {
        // readfile();
        cout << " Welcome ";
        _getch();
    }
    else
        cout << " Incorect Logon details, try again! " << endl;

    _getch();

    if (proceed ==1)
    {
        cout << " Logged on as Manager "; 
        managermenu();
    }


    if (proceed ==2)
    {
        cout << " Logged in as Barrista ";
        barristamenu();
    }




}

int logon()
{   // code here

    // read in username and password
    // check and return value to main method

    string username;
    char password[13];
    string pass;

    cout << " Enter username ";
    cin >>username;

    cout << " Enter Password ";
    cin >>pass;



    //cout<< pass.compare("password");

    if ((username.compare("manager")==0)&&(pass.compare("password")==0))
    return 1;

    if ((username.compare("barrista")==0)&&(pass.compare("password")==0))
    return 2;

    else
        return 0;

}


void writefile()
{   // code here
    ofstream outfile ("F:\coffee.txt", ios::out );

    for(int i = 0; !outfile.eof (); i++)
        {
            outfile << cl[i].bean_type << '\t'<< cl[i].stock_amount << '\t' << cl[i].purch_date << endl;

        }

    outfile.close ();

}


void readfile()
{   // code here
    ifstream infile ("F:\coffee.txt", ios::in );
    if(!infile)
    {
        cout << "Unable to open file " << endl;
    }

    for(int i = 0; !infile.eof (); i++)
        {
            infile >> cl[i].bean_type;
            infile >> cl[i].stock_amount;
            infile >> cl[i].purch_date;

            coffeecount++;

        }

    infile.close ();
}
void date()
{
    SYSTEMTIME time;

    GetLocalTime( &time );

    cout << time.wMonth << "/" << time.wDay << "/" << time.wYear << endl;
    cout << time.wHour << ":" << time.wMinute << endl;
}


void managermenu()
{   // screen output given place code araound 
        int choice;
    do
    {
        system("cls");

        cout << "\t\t MANAGER MENU \n";
        cout << "____________________________________________________\n";
        cout << "1. View current stock file\n";
        cout << "2. Add more stock\n";
        cout << "3. Barrista menu\n";
        cout << "7  to Exit\n";

        cout << "Enter choice: ";
        cin >> choice;

        switch (choice)
        {
            case 1: 
                 display(cl);
                break;
            case 2:  
                addstock();
                break;
            case 3:  
                barristamenu();
                break;
        }

    }
    while (choice != quit);
}

void barristamenu()
{   // screen output given place code araound 

        int choice;
    do
    {   
        system("cls");
        cout << "\t\t BARRISTA MENU \n";
        cout << "____________________________________________________\n";
        cout << "1. Make order\n";
        cout << "2. Update stock file\n";
        cout << "7  to Exit (or return to manager menu)\n";

        cout << "Enter choice: ";
        cin >> choice;

        switch(choice)

            case 1:
                    processorder(cl);
                    break;
            case 2:
                    addstock();
                    break:

    }
    while (choice != quit); 
}

void display(coffee_list coffee_list)
{   // code here
    system("cls");
    // print headings
    cout << "BEAN TYPE \t STOCK AMOUNT\t PURCHASE DATE \n\n";

// for each record
    for(int i = 0; i< MAX; i++)
    {   
        cout << cl[i].bean_type << "\t\t" << cl[i].stock_amount << "\t\t" << cl[i].purch_date << endl;
    }
    _getch();


}

void processorder(coffee_list& )
{
    int bean_choice;
    int bean_pos;
    int coffee_choice;
    int portions;
    string coffee;
    int num_cups;
    int total_portions;

    system("cls");

    cout << "select normal or decaffe" << endl;
    cout << "1. Normal" << endl;
    cout << "2. Decaffe" << endl;
    cout << "Select: ";

// screen output given place code araound 

    cout << "\n\n";
    cout << "Now select cofee type" << endl;
    cout << "1. Americano" << endl;
    cout << "2. Macchiato" << endl; 
    cout << "3. Espresso" << endl;
    cout << "4. Double Espresso" << endl;
    cout << "5. Cappuccino" << endl;
    cout << "6. Mocha" << endl;
    cin >> bean_choice;

    cout << "Make selection: ";
    cin >> coffee_choice;

// screen output given place code araound   

}
void addstock()
{   
    string bean;
    int amount;
    SYSTEMTIME time;
    GetLocalTime( &time );

// code here

}

Hi guys hope ur are all well!

I have a program im trying to finish and its not going well. I am quite new to C++ and am not the greatest.

I have code that ill post, but the problem is when i run the program with the readfile(); function within the main method it will display the 2 menus. When readfile(); is active it does not run?? Pls accept my appoligies if the code is not wraped properly its the first time i have posted!!

Cheers Brendan

Code tags are like this:

[code]

// paste code here

[/code]

When readfile(); is active it does not run??

Not sure what you mean by "active". main() is the entry point for all C++ programs. For a function to be executed, it needs to be either called by main () or called by some function somewhere that is called by main () or by a function called by a function called by a function called by main() or whatever. The point is that it all starts in main and you have a function call to readfile() in main, but it's commented out, so it's not going to be executed. You can completely delete the function and it will have no effect.

What are you trying to do? Why is the function commented out?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.