I am using Turbo C++ 3.0.
Things to be noted :
1.) I am very new to C++
2.) I can only use the above said compiler.
3.) List, vector, functions, classes, file-handling, structures, templates and objects cannot be used in the program as per my assignment.
Here's my Code:

#include <iostream.h>
#include <conio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>

int main()
{
char option;
float p,b,x,y,z,v,a,subtotal=0,price[100],quant[100],total,cash=0,change,peices=0,receipt,disc,net[100],products;
char* items[100];
START:
clrscr();
textcolor(WHITE);
textbackground(BLACK);
time_t now = time(0);
tm *ltm = localtime(&now);
srand( (unsigned)time( NULL ) );
receipt=rand();
gotoxy(50, 4);
    cout<<"WELCOME";

    gotoxy(52, 7);
    cout<<"TO";

    gotoxy(49, 10);
    cout<<"BIG BAZAAR";

    gotoxy(45, 16);
    cout<<"A. Create New Invoice";

    gotoxy(45, 19);
    cout<<"B. View Last Invoice";

    gotoxy(45, 22);
    cout<<"C. Exit\n";

    gotoxy(45, 25);
    option=getch();

if(option=='a'||option=='A')
{
    if(items[0]!=NULL)
    {
    for(p=0;p<10;p++)
    {
        items[p]=NULL;

    }

    }
    cout<<"How Many products do you want to purchase ? :";
    cin>>products;
    clrscr();
    gotoxy(35,0);
    cout<<"   ";

    gotoxy(35,1);
    cout<<"Retail Invoice";


    gotoxy(35,2);
    cout<<"Big Bazaar(FUTURE VALUE RETAIL LTD.)";

    gotoxy(35,4);
    cout<<"Vasant Square Mall\n";


    gotoxy(35,6);
    cout<<"Plot No.= 8, Community Centre,\n";


    gotoxy(35,8);
    cout<<"Sec B, Vasant Kunj, New Delhi-110070\n";


    gotoxy(35,10);
    cout<<"Tel No.: 011-46000786";


    gotoxy(35,12);
    cout<<"Helpline : 1800 200 2255";


    gotoxy(30,14);
    cout<<"************************************************";

    gotoxy(30,15);
    cout<<"*";

    gotoxy(77,15);
    cout<<"*";


    gotoxy(32,15);
    cout<<"ITEM DESCRIPTION    QTY      AMT    NET AMT";

    for(p=0,y=16,x=32,z=52,a=61,b=68;p<products;y++,p++)
    {
    gotoxy(x,y);
    cin>>items[p];

        gotoxy(z,y);
    cin>>quant[p];


    gotoxy(a,y);
    cin>>price[p];
    net[p]=price[p]*quant[p];
    gotoxy(b,y);
    cout<<net[p];

    subtotal=net[p]+subtotal;

    peices=quant[p]+peices;

    if(p!=products)
    {

            gotoxy(30,y);
            cout<<"*";

            gotoxy(77,y);
            cout<<"*";
        }

    }
    gotoxy(30,y);
        cout<<"*";

        gotoxy(77,y);
        cout<<"*";

    gotoxy(30,y+1);
    cout<<"************************************************";


    gotoxy(31,y+2);
    cout<<"Subtotal                            Rs "<<subtotal;


    gotoxy(31,y+3);
    cout<<"VAT                                    12.5%";

    total= (subtotal*12.5)/100+subtotal;

    gotoxy(70,y+4);
    cout<<"*****";

    if(subtotal<4000)
    {
        disc=0;
        total-=disc;
    }
    if(subtotal>=4000)
    {
        disc=100;
        total-=disc;
    }
    if(subtotal>=10000)
    {
        disc=1000;
        total-=disc;
    }
    if(subtotal>=50000)
    {
        disc=5000;
        total-=disc;
    }


    gotoxy(31,y+5);
    cout<<"Discount                            Rs "<<disc;


    gotoxy(31,y+6);
    cout<<"TOTAL AMOUNT                        Rs "<<total;


    gotoxy(31,y+7);
    cout<<"Cash Given                          Rs ";
    cin>>cash;

    change=cash-total;



    gotoxy(31,y+8);
    cout<<"Change Due                          Rs "<<change;


    gotoxy(31,y+9);
    cout<<"Peices Purchased :"<<peices;


    gotoxy(31,y+11);
    cout<<"Receipt No.:  "<<receipt;


    gotoxy(31,y+12);
    cout<<"Receipt Date and Time:  "<<ltm->tm_mday<<"/"<< 1 + ltm->tm_mon<<"/"<<1900 + ltm->tm_year<<"  "<< 1 + ltm->tm_hour << ":"<<1 + ltm->tm_min << ":"<< 1 + ltm->tm_sec << endl;

    gotoxy(31,y+14);
    cout<<"THANKS FOR SHOPPING FROM BIG BAZAAR\n";

    gotoxy(31,y+15);
    cout<<"INDIA KA NAYA BAZAAR!";
    getch();
    goto START;
}
if(option=='b'||option=='B')
{
    clrscr();
    if(cash==0)
    {
    cout<<"No invoice was created. \nPlease create a new one.";
    getch();
    goto START;
    }
    else
    {
    gotoxy(35,0);
    cout<<"Retail Invoice\n";


    gotoxy(35,2);
    cout<<"Big Bazaar(FUTURE VALUE RETAIL LTD.)\n";


    gotoxy(35,4);
    cout<<"Vasant Square Mall\n";


    gotoxy(35,6);
    cout<<"Plot No.= 8, Community Centre,\n";


    gotoxy(35,8);
    cout<<"Sec B, Vasant Kunj, New Delhi-110070\n";


    gotoxy(35,10);
    cout<<"Tel No.: 011-46000786";


    gotoxy(35,12);
    cout<<"Helpline : 1800 200 2255";


    gotoxy(30,14);
    cout<<"************************************************";

    gotoxy(30,15);
    cout<<"*";

    gotoxy(77,15);
    cout<<"*";


    gotoxy(32,15);
    cout<<"ITEM DESCRIPTION    QTY      AMT    NET AMT";

    for(p=0,y=16,x=32,z=52,a=61,b=68;p<100;y++,p++)
    {
    if(items[p]==NULL)
    {

        gotoxy(30,y);
            cout<<"*";

            gotoxy(77,y);
        cout<<"*";

            break;
        }
    else
        {

            gotoxy(30,y);
            cout<<"*";

            gotoxy(77,y);
            cout<<"*";
        }
        gotoxy(x,y);
    cout<<items[p];

        gotoxy(z,y);
    cout<<quant[p];

        gotoxy(a,y);
    cout<<price[p];

        gotoxy(b,y);
    cout<<net[p];

    }

    gotoxy(30,y);
    cout<<"************************************************";


    gotoxy(31,y+2);
    cout<<"Subtotal                            Rs "<<subtotal;


    gotoxy(31,y+3);
    cout<<"VAT                                    12.5%";

    gotoxy(70,y+4);
    cout<<"*****";


    gotoxy(31,y+5);
    cout<<"Discount                            Rs "<<disc;


    gotoxy(31,y+6);
    cout<<"TOTAL AMOUNT                        Rs "<<total;


    gotoxy(31,y+7);
    cout<<"Cash Given                          Rs "<<cash;


    gotoxy(31,y+8);
    cout<<"Change Due                          Rs "<<change;


    gotoxy(31,y+9);
    cout<<"Peices Purchased :"<<peices;


    gotoxy(31,y+11);
    cout<<"Receipt No.:  "<<receipt;


    gotoxy(31,y+12);
    cout<<"Receipt Date and Time:  "<<ltm->tm_mday<<"/"<< 1 + ltm->tm_mon<<"/"<<1900 + ltm->tm_year<<"  "<< 1 + ltm->tm_hour << ":"<<1 + ltm->tm_min << ":"<< 1 + ltm->tm_sec << endl;

    gotoxy(31,y+14);
    cout<<"THANKS FOR SHOPPING FROM BIG BAZAAR\n";

    gotoxy(31,y+15);
    cout<<"INDIA KA NAYA BAZAAR!";

    getch();

    goto START;
    }

}
if(option=='c'||option=='C')
{  char yn;
   cout<<"\nDo You Really Want To Exit(y/n)";
   cin>>yn;
    if(yn=='y')
    {
    return 0;
    }
    if(yn=='n')
    {
    goto START;
    }
}
else
{
    clrscr();
    cout<<"Option Entered is incorrect\n Please try again.";
    getch();
    goto START;
}
return 0;
}

Problem faced: Only one product can be entered after which the program closes on its own.

Recommended Answers

All 8 Replies

You need to put a loop around the entire program, such as from line 20 to about line 373 (just before the return statement).

It's hard to believe you are not allowed to use functions! No programmer in his/her right mind would write that big of program without using functions to make it more readable.

No programmer in his/her right mind would write that big of program without using functions to make it more readable.

To be fair, it would be drastically shorter without all of the Turbo C++isms. ;)

I would be thankful if you could provide me with a code snippet.

It's hard to believe you are not allowed to use functions! No programmer in his/her right mind would write that big of program without using functions to make it more readable.

Ans.) I know that, but it is an instruction given by my C++ Teacher.
Thanks, in advance for the snippet

Something like this maybe:

// right where you collect option the first time put this

cin >> option;
option = tolower(option);
while(option != 'c'){



} // right above return 0; you put this to close the while loop

I don't know if that is exactly what you're looking for, but it if you place it in the right place it will force the system to iterate through more than one of whatever you are processing. Like the comment above, I can't understand any instructor would every tell a student of C++ to not use functions or struct or objects becasue that is where the power of C++ really lies (at least in my opinion). Anyway, hope this helps.

float products;
\\some code here
cout<<"How Many products do you want to purchase ? :";
cin>>products;
for(p=0,y=16,x=32,z=52,a=61,b=68;p<products;y++,p++)
    {
    gotoxy(x,y);
    cin>>items[p];

        gotoxy(z,y);
    cin>>quant[p];


    gotoxy(a,y);
    cin>>price[p];
    net[p]=price[p]*quant[p];
    gotoxy(b,y);
    cout<<net[p];

    subtotal=net[p]+subtotal;

    peices=quant[p]+peices;

    if(p!=products)
    {

            gotoxy(30,y);
            cout<<"*";

            gotoxy(77,y);
            cout<<"*";
        }

    }

I am facing problem in this loop and desparately want your help.
Loop executes in a manner that after entering the product name, quantity and the rate, the program closes, even though it shold not be like this.
And thanks 'JamBlaster' and 'Ancient Dragon' for your efoorts. +1 to you.

why is products a float instead of an integer. How can you have anything but an integer for the number of products??? You can't have something like 2.5 products. And what data type is 'p' declared to be?

I can tell that you really are trying to learn here and if you want to learn read and think about what the Dragon above said about p not being an integer.

Below here you can find an altered version of your last post of code within a working for loop which takes in input and provides output. It is (obviously) just a piece of test code and it is intended for you to use to see a possible way that you could go about solving this particular problem. Check it out and try to understand why it works:

#include "stdafx.h"
#include <iostream>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{

    int products;
    int p, y, x, z, a, b;
    int items[100]; // don't know how big to go
    int quant[100]; // don't know how big to go
    float price[100]; // don't know how big to go
    float subtotal = 0;
    int peices = 0;
    float net[100]; // don't know how big to go


    //some code here
    cout<<"How Many products do you want to purchase ? :";
    cin>>products;
    for(p=0,y=16,x=32,z=52,a=61,b=68;p<products;y++,p++) {

        cout << endl << endl << "Item Number Please: ";
        cin>>items[p];
        cout << endl << endl << "Quantity Please: ";
        cin>>quant[p];
        cout << endl << endl << "Price of Item Please: ";
        cin>>price[p];
        net[p]=price[p]*quant[p];
        cout << endl << endl << "Net price of " << quant[p] << " of item number " << items[p] << " is: " << net[p];
        cout << endl << endl << "The subtotal is: ";
        subtotal=net[p]+subtotal;
        cout << subtotal;
        peices=quant[p]+peices;
        if(p!=products) {
            cout<<"*";
            cout<<"*";
        }

     }

    return 0;
}

Thanks for your efforts. I figured the problem out. In Turbo C++, the if and else statement in loop don't work and the compiler always takes into consideration, the first if statement. Instead we need to use the switch() function.

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.