I have Problem of some part of my program , my program is working but theres something wrong.
The output should be the one i chose in this part below should display on the on the official reciept page...this is my problem because the one i chose will not display on the last page ,
I'm a 1st year BSIT student in the Philippines , and i dont know what should i replace..
Example :
What do you want: 1//i chosed 1
T - Shirt P450//then this will appear
You want to buy it?(Y/N)//then this will appear
OFFICIAL RECIEPT//then this will come up
ITEM COST//and this is next will appear
????????? ?????//this part is my problem because instead it will display Item 1 which is the T - Shirt and 450 price it will display another item which you did not chose...Please help ..I appreciate your kindness..thank you.
include <cstdlib>
include <iostream>
include <string>
using namespace std;
int main(int argc, char *argv[])
{
string terminate;
char code;
char access;
int r;
char link[]={'1','2','3','4','5','6','7','8','9','10'};
string item[10]={"T-Shirt\t","Long Pants","Wallet\t","Cap\t","Underwear","Belt\t","Bags\t","Handkerchief","Perfumes","Short Pants"};
float sum = 0,vat = 0,vat1 = 0,mon = 0,total = 0;
int arrays[10]={450,800,185,150,150,130,400,50,180,500};
OK thanks ... i appreciate your kindness .. yes its an homework but its not my homework , its my friends homework she's a 2nd year Computer Engineering Student , i just tried if how i can make the program and if i can do it by myself but i found it really hard so i called for assistance , ill try to debug the program again until i will got the correct answer ..Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
After two years, I would imagine that your Computer Engineering student friend would be better placed to help you with this than us.
As I suggested post the assignment text so that we can tell what your are trying to achieve; because it is not apparent from your code.
I don't thing necessarily your problem is a debugging issue, I think it is a design issue. Come up with a design that works and code it rather than just coding without any design or analysis of the problem.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No!!!!!! This is the third time you have posted this question to separate threads. Use ONE thread.
At least this time you appear to have modified the code. However it still makes no sense to me. I am not suprised that the output is not right.
In this code
if(arrays[y]<=link[y])
sum = sum + arrays[y];
cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
the condition is only true when y = 7 so that arrays[7] == 50 and link[7] = '8' ASCII code 56 decimal). I think you have omitted the braces around this because it outputs a list of all items contrary to your description, so it still seems that you are not posting the same code you are running!
I can think of no connection between what link[] is initialised to and arrays[] which appears to be where you put the prices.
Have you ever bought anything in a shop. It seems very odd that you should ask how much cash someone has before you ask them what they want!
Currently it does not take much thinking about to see that teh code is not yet in good shape. The mistakes are so foolish that I am not sure how you got this far.
I am guessing that the code was in fact provided to you as a debugging exercise, and that you are attempting to get someone to do the work for you.
Until you start making sense, and adhering to forum etiquette, I think we shall cease this discussion.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
could somebody tell me what looping should i use ?
for(int y = 0;y<=9;y++)
{
if(arrays[y]<=link[y])
sum = sum + arrays[y];
cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
}
im confused what to put in if(arrays[y]<=??????) to display what I chosed in the first part ... and also i cant use * if * if I encode inside a string tupe array..
include <cstdlib>
include <iostream>
include <string>
using namespace std;
int main(int argc, char *argv[])
{
string terminate;
char code;
char access;
int r;
char link[]={'1','2','3','4','5','6','7','8','9','10'};
string item[10]={"T-Shirt\t","Long Pants","Wallet\t","Cap\t","Underwear","Belt\t","Bags\t","Handkerchief","Perfumes","Short Pants"};
float sum = 0,vat = 0,vat1 = 0,mon = 0,total = 0;
int arrays[10]={450,800,185,150,150,130,400,50,180,500};
do{
cout<<"Input password: ";
getline(cin,terminate);
}while(terminate!="guest"&&terminate!="GUEST");
cout<<"\t\t\tITEMS LIST"<<endl;
cout<<"\n\t\tCODE"<<endl;
for(int y=0;y<=9;y++)
{
cout<<"\t\t"<<link[y]<<endl;
}
cout<<"Input Cash: ";
cin>>mon;
do{
loop:
cout<<"What do you want?: ";
cin>>code;
for(int x=0;x<=9;x++)
{
if(arrays[x]<=code)
sum = sum + arrays[x];
}
switch(code){
case '1':
cout<<"ITEM - "<<item[0]<<"\t\t"<<"PRICE: P"<<arrays[0]<<endl;
break;
case '2':
cout<<"ITEM - "<<item[1]<<"\t\t"<<"PRICE: P"<<arrays[1]<<endl;
break;
case '3':
cout<<"ITEM - "<<item[2]<<"\t\t"<<"PRICE: P"<<arrays[2]<<endl;
break;
case '4':
cout<<"ITEM - "<<item[3]<<"\t\t"<<"PRICE: P"<<arrays[3]<<endl;
break;
case '5':
cout<<"ITEM - "<<item[4]<<"\t\t"<<"PRICE: P"<<arrays[4]<<endl;
break;
case '6':
cout<<"ITEM - "<<item[5]<<"\t\t"<<"PRICE: P"<<arrays[5]<<endl;
break;
case '7':
cout<<"ITEM - "<<item[6]<<"\t\t"<<"PRICE: P"<<arrays[6]<<endl;
break;
case '8':
cout<<"ITEM - "<<item[7]<<"\t\t"<<"PRICE: P"<<arrays[7]<<endl;
break;
case '9':
cout<<"ITEM - "<<item[8]<<"\t\t"<<"PRICE: P"<<arrays[8]<<endl;
break;
case '10':
cout<<"ITEM - "<<item[9]<<"\t\t"<<"PRICE: P"<<arrays[9]<<endl;
break;
default:
cout<<"INVALID INPUT !!"<<endl;
break;
}
cout<<"You want to buy it?(Y/N)";
cin>>access;
switch(access){
case 'N':
case 'n':
goto loop;
default:
cout<<"INVALID INPUT"<<endl;
}
}while(access!='Y'&&access!='y');
cout<<"\nOFFICIAL RECIEPT\n"<<endl;
cout<<"\t\tItems\t\t\t"<<"Cost"<<endl;
cout<<"Input Cash: ";
cin>>mon;
for(int y = 0;y<=9;y++)
{
if(arrays[y]<=link[y])
sum = sum + arrays[y];
cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
}
total = mon - sum;
vat = sum * .12f;
vat1 = sum - vat;
cout<<"VAT :"<<vat1<<endl;
cout<<"NON VAT :"<<'0'<<endl;
cout<<"12% VAT :"<<vat<<endl;
cout<<"TOTAL COST:"<<sum<<endl;
cout<<"CASH :"<<mon<<endl;
cout<<"CHANGE :"<<total<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What confuses me is why you hace coded what you did. Being a beginner is one thing, but it usually results in writing simpler code or nothing rather than writing nonsense and wondering why it does not work.
You have not addressed my questions:
> if(arrays[y]<=link[y])
What makes you thing that will do anything useful? You appear to be comparing the item proce with the item menu index. And I am not sure why it is in a loop in any case. You are only printing one item and you already know its index. Moreover the code does not do what you described, it has completly different errors, so it all sees suspicous.
I suggest that this whole loop:
> for(int y = 0;y<=9;y++)
> {
> if(arrays[y]<=link[y])
> sum = sum + arrays[y];
> cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
> }
BTW, surely you want to print teh item names and proces in that loop also!? A list of numbers is not very useful.
> im confused what to put in if(arrays[y]<=??????) to
> display what I chosed in the first part ...
You ar every confused. I don't know how you got in this mess. There is a difference between not knowing a programming language syntax and just not knowing how to think. This shows a lack of clarity of thought.
> and also i cant use * if * if I encode inside a string tupe array..
You can in C++ when using the std::string class. Or if using a C style string you use the strcmp() function. However in this case there is no requirement to do string comparisons.
I am assuming that this is homework? That being the case you should consult your course materials and your course tutor (that is what he is paid for), and of course attend class. You classmates may also be of assistance. I am sure that you understand that it would be inappropriate for anyone to simply provide you with a complete solution. Having said that It may help if you could post the exact assignment question, to make sure that teh advice given is appropriate. At teh moment I have suggested only fixes for what I think your code is intended to do.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
> my program is working but theres something wrong.
Then it is not working. In what useful sense of teh word is it working!?
If you fired up a word processor and it displayed different characters than the ones you typed, or a spreadsheet that calculated incorrect values, you would not call that working!
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have Problem of some part of my program , my program is working but theres something wrong.
The output should be the one i chose in this part below should display on the on the official reciept page...this is my problem because the one i chose will not display on the last page ,
I'm a 1st year BSIT student in the Philippines , and i dont know what should i replace..
Example :
What do you want: 1//i chosed 1
T - Shirt P450//then this will appear
You want to buy it?(Y/N)//then this will appear
OFFICIAL RECIEPT//then this will come up
ITEM COST//and this is next will appear
????????? ?????//this part is my problem because instead it will display Item 1 which is the T - Shirt and 450 price it will display another item which you did not chose...Please help ..I appreciate your kindness..thank you.
include <cstdlib>
include <iostream>
include <string>
using namespace std;
int main(int argc, char *argv[])
{
string terminate;
char code;
char access;
int r;
char link[]={'1','2','3','4','5','6','7','8','9','10'};
string item[10]={"T-Shirt\t","Long Pants","Wallet\t","Cap\t","Underwear","Belt\t","Bags\t","Handkerchief","Perfumes","Short Pants"};
float sum = 0,vat = 0,vat1 = 0,mon = 0,total = 0;
int arrays[10]={450,800,185,150,150,130,400,50,180,500};
}
OK thanks ... i appreciate your kindness .. yes its an homework but its not my homework , its my friends homework she's a 2nd year Computer Engineering Student , i just tried if how i can make the program and if i can do it by myself but i found it really hard so i called for assistance , ill try to debug the program again until i will got the correct answer ..Thanks.
After two years, I would imagine that your Computer Engineering student friend would be better placed to help you with this than us.
As I suggested post the assignment text so that we can tell what your are trying to achieve; because it is not apparent from your code.
I don't thing necessarily your problem is a debugging issue, I think it is a design issue. Come up with a design that works and code it rather than just coding without any design or analysis of the problem.
Clifford
No!!!!!! This is the third time you have posted this question to separate threads. Use ONE thread.
At least this time you appear to have modified the code. However it still makes no sense to me. I am not suprised that the output is not right.
In this code
the condition is only true when y = 7 so that arrays[7] == 50 and link[7] = '8' ASCII code 56 decimal). I think you have omitted the braces around this because it outputs a list of all items contrary to your description, so it still seems that you are not posting the same code you are running!
I can think of no connection between what link[] is initialised to and arrays[] which appears to be where you put the prices.
Have you ever bought anything in a shop. It seems very odd that you should ask how much cash someone has before you ask them what they want!
Currently it does not take much thinking about to see that teh code is not yet in good shape. The mistakes are so foolish that I am not sure how you got this far.
I am guessing that the code was in fact provided to you as a debugging exercise, and that you are attempting to get someone to do the work for you.
Until you start making sense, and adhering to forum etiquette, I think we shall cease this discussion.
Clifford
could somebody tell me what looping should i use ?
for(int y = 0;y<=9;y++)
{
if(arrays[y]<=link[y])
sum = sum + arrays[y];
cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
}
im confused what to put in if(arrays[y]<=??????) to display what I chosed in the first part ... and also i cant use * if * if I encode inside a string tupe array..
include <cstdlib>
include <iostream>
include <string>
using namespace std;
int main(int argc, char *argv[])
{
string terminate;
char code;
char access;
int r;
char link[]={'1','2','3','4','5','6','7','8','9','10'};
string item[10]={"T-Shirt\t","Long Pants","Wallet\t","Cap\t","Underwear","Belt\t","Bags\t","Handkerchief","Perfumes","Short Pants"};
float sum = 0,vat = 0,vat1 = 0,mon = 0,total = 0;
int arrays[10]={450,800,185,150,150,130,400,50,180,500};
do{
cout<<"Input password: ";
getline(cin,terminate);
}while(terminate!="guest"&&terminate!="GUEST");
cout<<"\t\t\tITEMS LIST"<<endl;
cout<<"\n\t\tCODE"<<endl;
for(int y=0;y<=9;y++)
{
cout<<"\t\t"<<link[y]<<endl;
}
cout<<"Input Cash: ";
cin>>mon;
do{
loop:
cout<<"What do you want?: ";
cin>>code;
for(int x=0;x<=9;x++)
{
if(arrays[x]<=code)
sum = sum + arrays[x];
}
switch(code){
case '1':
cout<<"ITEM - "<<item[0]<<"\t\t"<<"PRICE: P"<<arrays[0]<<endl;
break;
case '2':
cout<<"ITEM - "<<item[1]<<"\t\t"<<"PRICE: P"<<arrays[1]<<endl;
break;
case '3':
cout<<"ITEM - "<<item[2]<<"\t\t"<<"PRICE: P"<<arrays[2]<<endl;
break;
case '4':
cout<<"ITEM - "<<item[3]<<"\t\t"<<"PRICE: P"<<arrays[3]<<endl;
break;
case '5':
cout<<"ITEM - "<<item[4]<<"\t\t"<<"PRICE: P"<<arrays[4]<<endl;
break;
case '6':
cout<<"ITEM - "<<item[5]<<"\t\t"<<"PRICE: P"<<arrays[5]<<endl;
break;
case '7':
cout<<"ITEM - "<<item[6]<<"\t\t"<<"PRICE: P"<<arrays[6]<<endl;
break;
case '8':
cout<<"ITEM - "<<item[7]<<"\t\t"<<"PRICE: P"<<arrays[7]<<endl;
break;
case '9':
cout<<"ITEM - "<<item[8]<<"\t\t"<<"PRICE: P"<<arrays[8]<<endl;
break;
case '10':
cout<<"ITEM - "<<item[9]<<"\t\t"<<"PRICE: P"<<arrays[9]<<endl;
break;
default:
cout<<"INVALID INPUT !!"<<endl;
break;
}
cout<<"You want to buy it?(Y/N)";
cin>>access;
switch(access){
case 'N':
case 'n':
goto loop;
default:
cout<<"INVALID INPUT"<<endl;
}
}while(access!='Y'&&access!='y');
cout<<"\nOFFICIAL RECIEPT\n"<<endl;
cout<<"\t\tItems\t\t\t"<<"Cost"<<endl;
cout<<"Input Cash: ";
cin>>mon;
for(int y = 0;y<=9;y++)
{
if(arrays[y]<=link[y])
sum = sum + arrays[y];
cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
}
total = mon - sum;
vat = sum * .12f;
vat1 = sum - vat;
cout<<"VAT :"<<vat1<<endl;
cout<<"NON VAT :"<<'0'<<endl;
cout<<"12% VAT :"<<vat<<endl;
cout<<"TOTAL COST:"<<sum<<endl;
cout<<"CASH :"<<mon<<endl;
cout<<"CHANGE :"<<total<<endl;
system("PAUSE");
return EXIT_SUCCESS;
}
sorry for my stupidity , im just a begginer i just want to know or have an idea on what should i change on my program...
What confuses me is why you hace coded what you did. Being a beginner is one thing, but it usually results in writing simpler code or nothing rather than writing nonsense and wondering why it does not work.
You have not addressed my questions:
> if(arrays[y]<=link[y])
What makes you thing that will do anything useful? You appear to be comparing the item proce with the item menu index. And I am not sure why it is in a loop in any case. You are only printing one item and you already know its index. Moreover the code does not do what you described, it has completly different errors, so it all sees suspicous.
I suggest that this whole loop:
> for(int y = 0;y<=9;y++)
> {
> if(arrays[y]<=link[y])
> sum = sum + arrays[y];
> cout<<"\t\t"<<item[y]<<"\t\t"<<arrays[y]<<endl;
> }
should simply be replaced with:
cout<<"\t\t"<<item[code - 1]<<"\t\t"<<arrays[code - 1]<<endl;
Also the switch/case is entirely unnecessary and can simply be replaces with:
if( code > 0 && code <= 10 )
{
cout<<"ITEM - "<<item[code - 1]<<"\t\t"<<"PRICE: P"<<arrays[code - 1]<<endl;
}
else
{
cout<<"INVALID INPUT !!"<<endl;
}
And the link[] array is entirely redundant since it is not variable and is a simple arithmetic sequence. So for example, this:
> for(int y=0;y<=9;y++)
> {
> cout<<"\t\t"<<link[y]<<endl;
> }
simply becomes this:
for(int y=0;y<=9;y++)
{
cout << "\t\t" << y + 1 << endl ;
}
BTW, surely you want to print teh item names and proces in that loop also!? A list of numbers is not very useful.
> im confused what to put in if(arrays[y]<=??????) to
> display what I chosed in the first part ...
You ar every confused. I don't know how you got in this mess. There is a difference between not knowing a programming language syntax and just not knowing how to think. This shows a lack of clarity of thought.
> and also i cant use * if * if I encode inside a string tupe array..
You can in C++ when using the std::string class. Or if using a C style string you use the strcmp() function. However in this case there is no requirement to do string comparisons.
I am assuming that this is homework? That being the case you should consult your course materials and your course tutor (that is what he is paid for), and of course attend class. You classmates may also be of assistance. I am sure that you understand that it would be inappropriate for anyone to simply provide you with a complete solution. Having said that It may help if you could post the exact assignment question, to make sure that teh advice given is appropriate. At teh moment I have suggested only fixes for what I think your code is intended to do.
Clifford
> my program is working but theres something wrong.
Then it is not working. In what useful sense of teh word is it working!?
If you fired up a word processor and it displayed different characters than the ones you typed, or a spreadsheet that calculated incorrect values, you would not call that working!
Clifford