solve the questions!!!

Pages: 12
write and run a program that reads a six digit number and prints the sum of its six digits!!!!!
No. We do not solve problems just like that on this forum. Show us what code you have and we may help you debug it, sure, but we don't do all the work for you.

-Albatross
closed account (3TkL1hU5)
This is a pretty straight forward and simple assignment.. What makes you think you have a chance of passing any programming class if you're asking the internet to write the basic stuff for you? Not trying to be rude, only honest.

SealCodes
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
27
28
29
30
31
#include <iostream> // include standard I/O library

using namespace std; // access standard namespace

int main ()
{

	int a,b,c,d,e,f;

	int result;

	cout<<"Enter your Numbahs: ";
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;
	cin>>e;
	cin>>f;

	result = a+b+c+d+e+f;

	cout<<result;

	cin.ignore();
	cin.ignore();
	


return 0;

}



Not in any way condoning these type of outbursts and demanding help..but this seemed fun and I also am a beginner in C++... done in 5 seconds this.

While I'm here, can anyone explain me more about the input buffer and how i may escape it?


EDIT: o.O its supposed to be a 6 digit number not 6 consecutive digits?...hmmm
Last edited on
You are aware that you just solved someone's homework and are thumbing up laziness, whilst this is not really any kind of difficulty when you have basic C++ experience. (Which I believe you have, since you did it 5 seconds.)
But i didnt solve his problem. And I mention that I am not doing this for his own benefit and that i think his question was put in very silly.

I really am a nub myself and just trying to learn by participating on these forums other than just asking my own questions. besides i think i can figure out his real problem here..which is what im working on its quite interesting and a bit difficult.

Sorry Kyon if what i did seemed wrong, ill just attempt to solve his problem and keep it to myself.

EDIT: SOLVED yay so happy with my self...
Last edited on
It's wrong for many many reasons. Don't do it in future.

Lets list them shall we?

#1: We, being nubs ourselves could post incorrect code, which would hinder him further.
#2: He learns nothing from copying code from the interwebz and pasting it as his OWN solution.
#3: He in turn, turns into a lazy bastard and comes here for every homework solution that he needs done.
#4: Everyone else in the world realizes that they can get a free IT degree, so they all come here asking people to do their work for them FOR FREE.
#5: Time, space & the universe explodes and forms a black hole from too many morons who don't know how to program properly.
sorry guys i will not do it again!!!
the thing is that how to take 6 digit number seprately and add them....it would have been simple if it was 6 consecutive numbers...but it is 6 digit number????
Consider the number x=482371.

What function f(x) will yield the least signficant digit?
What function g(x) will yield everything but the least significant digit (ie, 48237)?
Ali sher do some experimenting - i really liked this assignment and it took me a little while but i got it and it was very fun. for example grab a paper and list a big number and ask yourself, "What can i do"(for example 482371) to pull out that 4? and assign it to the computers memory? Keeping in mind that your method shouuld work for now just 4 but any number the user inputs. the first number is actually the easiest to pull out i you use division
Last edited on
I haven't experimented with this question, but I thought the solution would involve the length() operator. Something like
1
2
3
4
for (int i = 0; i < number.length(); i++) { 
   array[i] = number.length[i];
}
sum_number = sum(array);
1
2
3
4
5
6
7
8
9
10
11
12
13
string num, temp;
num.length();
int sum = 0;

temp = num[i];

template<typename T>
void convertFromString(T &value, const string s)
{
  stringstream ss(s);
  ss >> value;  
}


something like this could solve the problem of vlad61
@stereoMatching - ? I did not have a problem though its interesting to se other solutions I solved said problem using devision and a combination of floor and ceil
void main()
{
int no,sum=0,n;
cout<<"your no:"
cin>>no;
while(n>=9)
{
no=n%10;
sum=sum+no;
n=n/10;
}
cout<<sum;
getch();
}
The key approach to this problem:
jsmith wrote:
Consider the number x=482371.

What function f(x) will yield the least signficant digit?
What function g(x) will yield everything but the least significant digit (ie, 48237)?

monichi's solution is very close:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
void main()
{
int no,sum=0,n;
cout<<"your no:"
cin>>no;
while(n>=9)
{
no=n%10;
sum=sum+no;
n=n/10;
}
cout<<sum;
getch();
}


As far as giving away answers, I wouldn't just give them away for nothing but if I felt compelled to experiement with something of my own, there's no reason not to post it.

One's choice to learn or not can and should not be forced. In reality copying solutions risks your integrity and will only get you so far. There's no faking it that won't be detected by the skilled interviewer.
Last edited on
closed account (3TkL1hU5)
moorecm wrote:
One's choice to learn or not can and should not be forced. In reality copying solutions risks your integrity and will only get you so far. There's no faking it that won't be detected by the skilled interviewer.


I will definitely agree with you. However, my problem is not so much in forcing them to learn or not, it's in not promoting laziness. If someone asked for me to write their code for them I would certainly not do it. When someone comes on here and posts their homework though, I do usually attempt to write my own for my own benefit and also so I can help them if there is something that I actually can. If someone comes here and posts what they have written and they still cannot figure it out then I would have no problem posting my code for them to use as an example.

I don't understand why anyone would ever choose to pursue studying a computer programming language or a computer science degree if they have no desire to learn or put forth an effort of their own. Any "<insert type here> Science" degree is going to require a lot of continuing education and effort. People should understand this before they spend thousands of dollars and years of time on a degree in something they will be lucky to succeed at.
I don't understand why anyone would ever choose to pursue studying a computer programming language or a computer science degree if they have no desire to learn or put forth an effort of their own.


I think you answered that question in your previous paragraph: laziness combined with shortsightedness. The goal in college
is to graduate. To graduate you need to pass your classes. A freshman is most likely not thinking anything about their future
beyond college.

The truth is that in my years of professional experience I have seen quite a number of people with CS degrees who could
barely tell the difference between a compiler and a word processor.


closed account (Lv0f92yv)
The truth is that in my years of professional experience I have seen quite a number of people with CS degrees who could
barely tell the difference between a compiler and a word processor.


[shudders]I promise, if I get my degree in CS (which I hope to), I will not be one of those people.

Last edited on
It would be good if Uni will put our area of focus in our degree besides CS.

E.g
Degree in Computer Science (Business Information Systems)
Degree in Computer Science (Artificial Intelligence)
Degree in Computer Science (Hardware-Software Interfacing)
etc etc

The parenthesis inside may give the employers some inkling on the graduate area of focus. If he is CS trained but in BIS, then he cannot expect the person to know a lot on data structures, algorithms, AI etc although most are covered in the first year of studies as mandatory modules.

Even if the degree did not put, our transcripts should list down the modules we take and that will give the employer our area of focus.
Pages: 12