470,810 Members | 1,007 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,810 developers. It's quick & easy.

problems with my program again!

hello everyone!
my program is not working properly,
it is not summing the values that i entered.
It should take the double values and add them and also take strings and
makes the * as a multiplacation .

thanks !!!
begum
here is my program

#include<iostream>
#include<string>
#include<iomanip>
#define MAX_INPUT_SIZE 100
using namespace std;

char language;
char temp;
int i;
int k;
double i_error;
double no_star;
char e;
char s;
int main()
{
cout<<"<T>urkce or <E>nglish :";
cin>>language;

while(1)
{
if(language=='E' ||language=='e')
{
cout<<"Enter prices or <S>top:";
cin>>s;if(s =='S' ||s=='s') break;

}
else if(language=='T'||language=='t')
{
cout<<"Fiyat girin veya <Sdur:";
cin>>s;if(s =='S' ||s=='s') break;

}
char temp[MAX_INPUT_SIZE]; //input,
char array; //en basta hepsi NULL'a esit
char part1[MAX_INPUT_SIZE],part2[MAX_INPUT_SIZE] ;
// char array; // en basta hepsi NULL'a esit
int k=0;
int current_operand=1;
double sum, sum1, sum2, total;


if(i_error==0) //processing input
{
for(i=0; i<=MAX_INPUT_SIZE; i++)
{
if(temp[i]!='*'&&current_operand==1&&temp[i]!=NULL)
{
part1[i]=temp[i];
}
if(temp[i]!='*'&&current_operand==2&&temp[i]!=NULL)
{
part2[k]=temp[i];
k++;
}

if(temp[i]=='*')
{
current_operand=2;
}
}

sum1=atof(part1);
sum2=atof(part2);

if(no_star)
{
sum=sum1;
}
if(!no_star)
{
sum=sum1*sum2;
}

total=total+sum;
}

if(language=='E' ||language=='e')
{
cout<<"The total is "<<setw(12)<<total<< "$ and VAT is "
<<setw(12)<<total*(0.12)<<"$."<<endl;

}
if(language=='T'||language=='t')
{
cout<<"Toplam "<<setw(12)<<total<< "YTL ve
KDV"<<setw(12)<<total*(0.12)<<"YTL."<<endl;
}
if(language=='E'||language=='e')
{
cout<<"<N>ext or <Q>uit:" ;
}
if(language=='T'||language=='t')
{
cout<<"<D>evam veya <C>ikis:";
}

cin>>e;

if(e=='N'||e=='n'||e=='D'||e=='d')
{
system("cls");
}
if(e=='Q'||e=='q'||e=='C'||e=='c')
{
return 0;
}
return 0;
}
}

Dec 6 '06 #1
2 1108

"begum" <be*******@gmail.comwrote in message
news:11*********************@n67g2000cwd.googlegro ups.com...
hello everyone!
my program is not working properly,
it is not summing the values that i entered.
It should take the double values and add them and also take strings and
makes the * as a multiplacation .

thanks !!!
begum
here is my program
Ever heard of a debugger? Step through the program and see what it's doing.

Or add cout statements at key points to report whether you reach certain
points and what values exist at those points, to see where things are going
right/wrong.

-Howard
Dec 6 '06 #2
On 6 Dec 2006 11:56:16 -0800 in comp.lang.c++, "begum"
<be*******@gmail.comwrote,
>my program is not working properly,
it is not summing the values that i entered.
I see that you define:
char s;
Then later you have:
cout<<"Enter prices or <S>top:";
cin>>s;
So all that can be entered is a single char. How is the user supposed
to enter any prices, if he can enter only a single char?
char temp[MAX_INPUT_SIZE]; //input,
char array; //en basta hepsi NULL'a esit
char part1[MAX_INPUT_SIZE], part2[MAX_INPUT_SIZE];
These variables are never initialized or read in.
Also, it is a bad idea to have a variable named "array" that is not an
array.

Dec 7 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by stu7 | last post: by
7 posts views Thread by jmac | last post: by
5 posts views Thread by Madison Kelly | last post: by
2 posts views Thread by Olaf Baeyens | last post: by
2 posts views Thread by Mike | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.