divide changed string for int by 10

Hi I have an exercise to make that I should know on examp. Exercise:
Read sequence of numbers, stop reading on char '!'. Print max, min and avarage number digit



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{
string sequence;
int a,max=0,min=8,avarage=0,n,ziom;
cout<<"Write a sequence numbers, with '!' at the end of sequence you want to figure out "<<endl;
getline(cin,sequence);

for(a=0,n=sequence.size();n>0;n--,ziom/=10)
{
stringstream(sequence)>>ziom; //I've changing string for int
a=ziom%10; //I've use it to read last number, and it work well, anyway divide ziom by 10 didn't and I don't know why.
cout<<a<<endl;
cout<<ziom<<endl;
a>max ? max=a : max=max;
a<min ? min=a : min = min;
}
cout<<"Najwieksza liczba ciagu = "<<max<<endl;
cout<<"Najmniejsza liczba ciagu = "<<min<<endl;
cout<<"Srednia ciagu = "<<avarage<<endl;
cout<<"a ="<<a<<endl;
return 0;
}


Maybe some know how I can divide ziom (string for int) by 10. Ziom didn't change and I don't know why, it should be divide by 10 in every repeat.
If you want ziom divided by 10, ziom = ziom/10;.
Usualy it works well, but not now. Ziom didin't change after i divide by 10. I think reason is that I've changed from string to int, by command stringstream(sequence)>>ziom; And right now I don't know what to do, to change that.

PS. ziom/=10; and ziom=ziom/10; is the same command.
I didn't notice that division. Of course this is because you're reading a new number into ziom on every cycle. The old value keeps getting overwritten. You need to use two loops. Outer to read numbers and inner to find their digits.
i think u want something like this.



#include<iostream>
#include<string>
#include<sstream>
using namespace std;
int main()
{


int a,max=0,min=8,avarage=0,n,ziom;
string sequence;
cout<<"Write a sequence numbers, with '!' at the end of sequence you want to figure out "<<endl;
getline(cin,sequence);
max = sequence.length();
avarage = sequence.length()/2 + sequence.length()%2;
min = sequence.length() - sequence.length() +1;


cout << " max Size is : "<<max <<endl;
cout << " avrage Size is : "<<avarage <<endl;
cout << " min Size is : "<< min <<endl;

system ("PAUSE");
}
Topic archived. No new replies allowed.