greenberet
October 13th, 2011, 11:20 AM
Hey guys, i`ve just started studying programming and i`ve run into a problem i don`t know how to fix, its very very basic, but i`m a newbie, anyway i how you can help me out, because i saw someone with a similar program, but couldn`t quite understand how to fix it in my program.
#include <iostream>
using namespace std;
int main()
{
int a, b=0, n=0, c, ok;
double summa;
do
{
summa = 0;
cout << "Ievadi naturalu skaitli" << endl;
cin >> a;
if (a >= 0)
{
n=0;
if (a==0)
cout <<a<<endl;
while (a!=0)
{
b = a % 10;
a=a/10;
summa=summa+b;
n++;
}
cout << summa/n << endl;
}
else
{
cout <<"Ievaditais skaitlis ir negativs";
}
cout << " Vai turpinaat (1) vai beigt (0)?" << endl;
cin >> ok;
} while (ok == 1);
return 0;
}
when i enter 0 in the consule, he gives out the asked for 0 but the program also adds "nan" at the end, how do i get rid of it?
thanks for the support.
#include <iostream>
using namespace std;
int main()
{
int a, b=0, n=0, c, ok;
double summa;
do
{
summa = 0;
cout << "Ievadi naturalu skaitli" << endl;
cin >> a;
if (a >= 0)
{
n=0;
if (a==0)
cout <<a<<endl;
while (a!=0)
{
b = a % 10;
a=a/10;
summa=summa+b;
n++;
}
cout << summa/n << endl;
}
else
{
cout <<"Ievaditais skaitlis ir negativs";
}
cout << " Vai turpinaat (1) vai beigt (0)?" << endl;
cin >> ok;
} while (ok == 1);
return 0;
}
when i enter 0 in the consule, he gives out the asked for 0 but the program also adds "nan" at the end, how do i get rid of it?
thanks for the support.