B
begum
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: <S> dur: ";
else
cout<<"Enter prices or <S> stop: ";
cin>>test;
if(test[0]!='S'){
for(int i=0;test!=NULL;i++){
if(test == '*'){
check=true;
i++;
j=0;
}
if(check==true){
s1[j]=test;
}
else{
s[j]=test;
cout<<test<<"\n";
u+=atoi(test);
cout<<u;
x=u;
p+=x;
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;
}
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: <S> dur: ";
else
cout<<"Enter prices or <S> stop: ";
cin>>test;
if(test[0]!='S'){
for(int i=0;test!=NULL;i++){
if(test == '*'){
check=true;
i++;
j=0;
}
if(check==true){
s1[j]=test;
}
else{
s[j]=test;
cout<<test<<"\n";
u+=atoi(test);
cout<<u;
x=u;
p+=x;
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;
}