Spadoof
Member
Dear readers,
I am having trouble with a C++ and I was wondering if anyone could help. I feel semi-ashamed writing this post because it seems like it should be so simple but its not clicking in my head. For a class I am currently attending, we are supposed to take a file full of poorly written code, figure out what it is supposed to do and rewrite it to be clear and working properly. Here is the code:
#include <iostream>
int main()
{
std::cout << "Enter values, control-d to quit:";
int s=0;
int c=0,limit=100;
int i;
while(std::cin>>i)
{s=s+i;
c=c+1;
}if(c!=0)
{
double a=s/c;
std::cout<<"s"<<c
<<"is"<<s
<<"ave"<<a
<<"\n";
return 0;
}
else
{
std::cout<<"No values input.\n";
return 1;
}
}
If anyone has a clue as to what this is supposed to to do, please tell me. Sorry for bothering you guys with an this kind of post. I appriciate your help.
-Spadoof :gp2x
I am having trouble with a C++ and I was wondering if anyone could help. I feel semi-ashamed writing this post because it seems like it should be so simple but its not clicking in my head. For a class I am currently attending, we are supposed to take a file full of poorly written code, figure out what it is supposed to do and rewrite it to be clear and working properly. Here is the code:
#include <iostream>
int main()
{
std::cout << "Enter values, control-d to quit:";
int s=0;
int c=0,limit=100;
int i;
while(std::cin>>i)
{s=s+i;
c=c+1;
}if(c!=0)
{
double a=s/c;
std::cout<<"s"<<c
<<"is"<<s
<<"ave"<<a
<<"\n";
return 0;
}
else
{
std::cout<<"No values input.\n";
return 1;
}
}
If anyone has a clue as to what this is supposed to to do, please tell me. Sorry for bothering you guys with an this kind of post. I appriciate your help.
-Spadoof :gp2x
Last edited by a moderator: