I have the following code, that deals with a grocery store and items, when I run it after compling it(which it finds no errors) and then go to debug it it starts with the MS-Dos Screen and then just sits there. It is suppose to say in the Ms-Dos Screen, press any key to continue. But it doesn't can someone please look at it for me and maybe lend a helping hand. I am totally lost in this class and do not know why it is doing it!
Thank you :yes:
here is the code since I don't know how to upload it
// Lindsay Schiller
//
// Grocery
// 10/28/04
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
const int maxs = 100;
void init(int id[maxs], int unitssold[maxs], double unitprice[maxs],
double unitsales[maxs])
{
int i;
for (i = 0; i < maxs; i++)
{
id[i] = -1;
unitssold[i] = 0;
unitprice[i] = 0;
unitsales[i] = 0;
}
}
void reedem (int id[maxs], int unitssold[maxs], double unitprice[maxs],
int &nums, string names[maxs])
{
int i;
ifstream inf;
inf.open("grocery.txt");
i = 0;
while (!inf.eof())
{
inf >> id[i] >> names[i] >> unitssold[i] >> unitprice[i];
i++;
}
nums = i;
}
void calctot(int id[], int unitssold[], double unitprice[],
double unitsales[], int &unitquant, double &totsales,
int nums)
{
int i;
for (i = 0; i < nums; i++)
{
unitsales[i] = unitssold[i] * unitprice[i];
unitquant = unitssold[i] + unitquant;
totsales = unitsales[i] + totsales;
}
}
void swapint (int &a, int &b)
{
int temp;
temp = a;
a = b;
b = temp;
}
void swapdob (double &a, double&b)
{
double temp;
temp = a;
a = b;
b = temp;
}
void swapstr (string &a, string &b)
{
string temp;
temp = a;
a = b;
b = temp;
}
void swapchar (char &a, char &b)
{
char temp;
temp = a;
a = b;
b = temp;
}
void sortem (int id[], int unitssold[], double unitprice[],
double unitsales[], int nums, string names[])
{
int i,j;
for (j = 0; j < nums; j++)
for (i = 0; i < nums-1; i++)
if (id[i] > id[i+1])
{
swapint(id[i], id [i+1]);
swapint(unitssold[i], unitssold[i+1]);
swapdob(unitprice[i], unitprice[i+1]);
swapdob(unitsales[i], unitsales[i+1]);
swapstr(names[i],names [i + 1]);
}
}
void rsales( double unitsales[], int &a, int &b, int &c,
int &d, int nums)
{
int i;
for (i = 0; i < nums; i++)
if(unitsales[i] >= 500.00)
a = a + 1;
else if (unitsales[i] >= 250.00)
b = b + 1;
else if (unitsales[i] >= 100.00)
c = c + 1;
else
d = d + 1;
}
void printt (int unitquat, double totsales, ofstream &outf)
{
outf.setf(ios::fixed);
outf.precision(2);
outf << setw(35) << "----" << setw(30) << "------" << endl;
outf << setw(35) << unitquat << setw(30) << totsales << endl;
}
void print (int id[], string names[], int unitssold[], double unitprice[],
int nums, ofstream &outf)
{
int i;
outf.setf(ios::fixed);
outf.precision(2);
outf << setw(3) << "ID's" << setw(8) << "Product" << setw(25) << "Units Sold"
<< setw(15) << "Unit Price" << setw(15) << endl;
outf << setw(1) << "===================================================="
<<endl;
for (i = 0; i < nums; i++)
{
outf << setw (3) << id[i] << " ";
outf.setf(ios::left);
outf << setw(15) << names[i];
outf.unsetf(ios::left);
outf << setw(15) << unitssold [i]
<< setw(15) << unitprice[i] << endl;
}
outf <<endl << endl << endl;
}
void print2 (int id[], string names[], int unitssold[], double unitprice[], double unitsales[],
int nums, ofstream &outf)
{
int i;
outf.setf(ios::fixed);
outf.precision(2);
outf << setw(3) << "ID's" << setw(8) << "Product" << setw(25) << "Units Sold"
<< setw(15)<< "Unit Price" << setw(15) << "Total Sales" << endl;
outf << setw(1)
<< "==================================================================="
<<endl;
for (i = 0; i < nums; i++)
{
outf << setw (3) << id[i] << " ";
outf.setf(ios::left);
outf << setw(15) << names[i];
outf.unsetf(ios::left);
outf << setw(15) << unitssold [i]
<< setw(15) << unitprice[i] << setw(15) << unitsales[i]
<< endl;
}
}
void main()
{
int id[maxs], nums = maxs;
int unitssold[maxs], unitquat = 0;
double unitprice[maxs];
double unitsales[maxs], totsales = 0;
string names[maxs];
ofstream outf;
outf.open("grocery.out");
init(id, unitssold, unitprice, unitsales);
reedem(id, unitssold, unitprice, nums, names);
calctot (id, unitssold, unitprice, unitsales,
unitquat, totsales, nums);
print (id,names, unitssold, unitprice, nums, outf);
sortem(id, unitssold, unitprice, unitsales, nums, names);
print2 (id,names, unitssold, unitprice, unitsales, nums, outf);
printt (unitquat, totsales, outf);
}
Question
thankins
I have the following code, that deals with a grocery store and items, when I run it after compling it(which it finds no errors) and then go to debug it it starts with the MS-Dos Screen and then just sits there. It is suppose to say in the Ms-Dos Screen, press any key to continue. But it doesn't can someone please look at it for me and maybe lend a helping hand. I am totally lost in this class and do not know why it is doing it!
Thank you :yes:
here is the code since I don't know how to upload it
// Lindsay Schiller // // Grocery // 10/28/04 #include <iostream> #include <fstream> #include <iomanip> #include <string> using namespace std; const int maxs = 100; void init(int id[maxs], int unitssold[maxs], double unitprice[maxs], double unitsales[maxs]) { int i; for (i = 0; i < maxs; i++) { id[i] = -1; unitssold[i] = 0; unitprice[i] = 0; unitsales[i] = 0; } } void reedem (int id[maxs], int unitssold[maxs], double unitprice[maxs], int &nums, string names[maxs]) { int i; ifstream inf; inf.open("grocery.txt"); i = 0; while (!inf.eof()) { inf >> id[i] >> names[i] >> unitssold[i] >> unitprice[i]; i++; } nums = i; } void calctot(int id[], int unitssold[], double unitprice[], double unitsales[], int &unitquant, double &totsales, int nums) { int i; for (i = 0; i < nums; i++) { unitsales[i] = unitssold[i] * unitprice[i]; unitquant = unitssold[i] + unitquant; totsales = unitsales[i] + totsales; } } void swapint (int &a, int &b) { int temp; temp = a; a = b; b = temp; } void swapdob (double &a, double&b) { double temp; temp = a; a = b; b = temp; } void swapstr (string &a, string &b) { string temp; temp = a; a = b; b = temp; } void swapchar (char &a, char &b) { char temp; temp = a; a = b; b = temp; } void sortem (int id[], int unitssold[], double unitprice[], double unitsales[], int nums, string names[]) { int i,j; for (j = 0; j < nums; j++) for (i = 0; i < nums-1; i++) if (id[i] > id[i+1]) { swapint(id[i], id [i+1]); swapint(unitssold[i], unitssold[i+1]); swapdob(unitprice[i], unitprice[i+1]); swapdob(unitsales[i], unitsales[i+1]); swapstr(names[i],names [i + 1]); } } void rsales( double unitsales[], int &a, int &b, int &c, int &d, int nums) { int i; for (i = 0; i < nums; i++) if(unitsales[i] >= 500.00) a = a + 1; else if (unitsales[i] >= 250.00) b = b + 1; else if (unitsales[i] >= 100.00) c = c + 1; else d = d + 1; } void printt (int unitquat, double totsales, ofstream &outf) { outf.setf(ios::fixed); outf.precision(2); outf << setw(35) << "----" << setw(30) << "------" << endl; outf << setw(35) << unitquat << setw(30) << totsales << endl; } void print (int id[], string names[], int unitssold[], double unitprice[], int nums, ofstream &outf) { int i; outf.setf(ios::fixed); outf.precision(2); outf << setw(3) << "ID's" << setw(8) << "Product" << setw(25) << "Units Sold" << setw(15) << "Unit Price" << setw(15) << endl; outf << setw(1) << "====================================================" <<endl; for (i = 0; i < nums; i++) { outf << setw (3) << id[i] << " "; outf.setf(ios::left); outf << setw(15) << names[i]; outf.unsetf(ios::left); outf << setw(15) << unitssold [i] << setw(15) << unitprice[i] << endl; } outf <<endl << endl << endl; } void print2 (int id[], string names[], int unitssold[], double unitprice[], double unitsales[], int nums, ofstream &outf) { int i; outf.setf(ios::fixed); outf.precision(2); outf << setw(3) << "ID's" << setw(8) << "Product" << setw(25) << "Units Sold" << setw(15)<< "Unit Price" << setw(15) << "Total Sales" << endl; outf << setw(1) << "===================================================================" <<endl; for (i = 0; i < nums; i++) { outf << setw (3) << id[i] << " "; outf.setf(ios::left); outf << setw(15) << names[i]; outf.unsetf(ios::left); outf << setw(15) << unitssold [i] << setw(15) << unitprice[i] << setw(15) << unitsales[i] << endl; } } void main() { int id[maxs], nums = maxs; int unitssold[maxs], unitquat = 0; double unitprice[maxs]; double unitsales[maxs], totsales = 0; string names[maxs]; ofstream outf; outf.open("grocery.out"); init(id, unitssold, unitprice, unitsales); reedem(id, unitssold, unitprice, nums, names); calctot (id, unitssold, unitprice, unitsales, unitquat, totsales, nums); print (id,names, unitssold, unitprice, nums, outf); sortem(id, unitssold, unitprice, unitsales, nums, names); print2 (id,names, unitssold, unitprice, unitsales, nums, outf); printt (unitquat, totsales, outf); }Then here is the input file
Link to comment
Share on other sites
4 answers to this question
Recommended Posts