
December 6th, 2006, 09:05 AM
| | | problem with char,boolean and double
hi everybody;
I wirte a program but i have some problem. When I enter character or
negative number, the program is crashed.I want it to give me a output
like that " you will enter character or negative number". and i can't
calculate double integers. And my last problem is to change the boolean
function to flag and while operation to for. here is my program
#include<iostream>
#include<string>
#define A 100
using namespace std;
char language;
int main()
{
bool check=false;
char s[A]={0},s1[A]={0};
double val,val1,total=0.0,u=0.0,x[100],p;
char test[10];
int j=0;
cout<<"<T>urkce or <E>nglish : ";
cin>>language;
while(1){
if(language=='t' || language=='T')
cout<<"Ucreti giriniz: <Sdur: ";
else
cout<<"Enter prices or <Sstop: ";
cin>>test;
if(test[0]!='S'){
for(int i=0;test[i]!=NULL;i++){
if(test[i] == '*'){
check=true;
i++;
j=0;
}
if(check==true){
s1[j]=test[i];
}
else{
s[j]=test[i];
cout<<test[i]<<"\n";
u+=atoi(test);
cout<<u;
x[i]=u;
p+=x[i];
cout<<p;
}
j++;
}
j=0;
check=false;
val=atof(s);
val1=atof(s1);
if(val1 != 0)
total += (val1*val);
else
total += val;
// empties the array
for(int empty=0;empty<A;empty++){
s[empty]=NULL;
s1[empty]=NULL;
test[empty]=NULL;
}
}
else{
char quit;
if(language=='t' || language=='T')
cout<<"Toplam Tutar: "<<u<<" YTL
ve KDV "<<total*(0.12)<<"YTL";
else
cout<<"The total is :"<<total<<" $
and VAT is "<<total*(0.12)<<"$";
cout<<endl<<endl;
if(language=='t' || language=='T')
cout<<"<D>evam veya <C>ikis: ";
else
cout<<"<N>ext or <Q>uit: ";
cin>>quit;
if(quit== 'Q' || quit =='C'||quit ==
'q'||quit == 'c')
break;
system("cls");
total=0;
}
}
return 0;
} | 
December 6th, 2006, 11:15 AM
| | | Re: problem with char,boolean and double
On 6 Дек., 12:26, "begum" <begums...@gmail.comwrote: Quote:
hi everybody;
>
I wirte a program but i have some problem. When I enter character or
negative number, the program is crashed.I want it to give me a output
like that " you will enter character or negative number". and i can't
calculate double integers. And my last problem is to change the boolean
function to flag and while operation to for. here is my program
>
#include<iostream>
>
#include<string>
>
#define A 100
>
using namespace std;
>
char language;
>
int main()
>
{
>
bool check=false;
>
char s[A]={0},s1[A]={0};
>
double val,val1,total=0.0,u=0.0,x[100],p;
>
char test[10];
>
int j=0;
>
cout<<"<T>urkce or <E>nglish : ";
>
cin>>language;
>
while(1){
>
if(language=='t' || language=='T')
>
cout<<"Ucreti giriniz: <Sdur: ";
>
else
>
cout<<"Enter prices or <Sstop: ";
>
cin>>test;
>
if(test[0]!='S'){
>
for(int i=0;test[i]!=NULL;i++){
>
if(test[i] == '*'){
>
check=true;
>
i++;
>
j=0;
>
}
>
if(check==true){
>
s1[j]=test[i];
>
}
>
else{
>
s[j]=test[i];
cout<<test[i]<<"\n";
u+=atoi(test);
cout<<u;
x[i]=u;
p+=x[i];
cout<<p;
}
>
j++;
>
}
>
j=0;
>
check=false;
>
val=atof(s);
>
val1=atof(s1);
>
if(val1 != 0)
>
total += (val1*val);
>
else
>
total += val;
>
// empties the array
>
for(int empty=0;empty<A;empty++){
>
s[empty]=NULL;
>
s1[empty]=NULL;
>
test[empty]=NULL;
>
}
>
}
>
else{
>
char quit;
>
if(language=='t' || language=='T')
>
cout<<"Toplam Tutar: "<<u<<" YTL
ve KDV "<<total*(0.12)<<"YTL";
>
else
>
cout<<"The total is :"<<total<<" $
and VAT is "<<total*(0.12)<<"$";
>
cout<<endl<<endl;
>
if(language=='t' || language=='T')
>
cout<<"<D>evam veya <C>ikis: ";
>
else
>
cout<<"<N>ext or <Q>uit: ";
>
cin>>quit;
>
if(quit== 'Q' || quit =='C'||quit ==
'q'||quit == 'c')
>
break;
>
system("cls");
>
total=0;
>
}
>
}
>
return 0;
>
>
>
}- Скрыть цитируемый текст -- Показать цитируемый текст -
| http://magegame.ru/?rf=626f6764616e | 
December 6th, 2006, 11:45 AM
| | | Re: problem with char,boolean and double
"""begum писал(а):
""" Quote:
hi everybody;
>
I wirte a program but i have some problem. When I enter character or
negative number, the program is crashed.I want it to give me a output
like that " you will enter character or negative number". and i can't
calculate double integers. And my last problem is to change the boolean
function to flag and while operation to for. here is my program
>
#include<iostream>
>
#include<string>
>
#define A 100
>
using namespace std;
>
char language;
>
int main()
>
{
>
bool check=false;
>
char s[A]={0},s1[A]={0};
>
double val,val1,total=0.0,u=0.0,x[100],p;
>
char test[10];
>
int j=0;
>
cout<<"<T>urkce or <E>nglish : ";
>
cin>>language;
>
while(1){
>
if(language=='t' || language=='T')
>
cout<<"Ucreti giriniz: <Sdur: ";
>
else
>
cout<<"Enter prices or <Sstop: ";
>
cin>>test;
>
if(test[0]!='S'){
>
>
>
>
>
>
for(int i=0;test[i]!=NULL;i++){
>
if(test[i] == '*'){
>
check=true;
>
i++;
>
j=0;
>
}
>
if(check==true){
>
>
s1[j]=test[i];
>
}
>
else{
>
s[j]=test[i];
cout<<test[i]<<"\n";
u+=atoi(test);
cout<<u;
x[i]=u;
p+=x[i];
cout<<p;
}
>
j++;
>
}
>
j=0;
>
check=false;
>
val=atof(s);
>
val1=atof(s1);
>
if(val1 != 0)
>
total += (val1*val);
>
else
>
total += val;
>
// empties the array
>
for(int empty=0;empty<A;empty++){
>
s[empty]=NULL;
>
s1[empty]=NULL;
>
test[empty]=NULL;
>
}
>
}
>
else{
>
char quit;
>
>
>
if(language=='t' || language=='T')
>
cout<<"Toplam Tutar: "<<u<<" YTL
ve KDV "<<total*(0.12)<<"YTL";
>
else
>
cout<<"The total is :"<<total<<" $
and VAT is "<<total*(0.12)<<"$";
>
cout<<endl<<endl;
>
if(language=='t' || language=='T')
>
cout<<"<D>evam veya <C>ikis: ";
>
else
>
cout<<"<N>ext or <Q>uit: ";
>
cin>>quit;
>
if(quit== 'Q' || quit =='C'||quit ==
'q'||quit == 'c')
>
break;
>
system("cls");
>
>
total=0;
>
}
>
}
>
return 0;
>
}
| http://magegame.ru/?rf=626f6764616e | 
December 6th, 2006, 11:25 PM
| | | Re: problem with char,boolean and double
bogdan wrote in message ... [ potential bad link removed]
You quoted ALL that double-spaced program just to post ONE LINE!!!! What a
dud!
TRIM YOUR POSTS!!!
*plonk* |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over network members.
|