help required

Pages: 12
Sep 16, 2013 at 4:54pm
Write your question here.
1-Input: Take integer inputs from the user until she enters a negative number.
Output: The smallest of all the non-negative numbers entered by the user



2-Input: Take integer inputs from the user until she enters a negative number.
Output: The smallest and the 2nd smallest of all the non-negative numbers entered

3-Input: A non-negative integer n
Output: The T-number at index n, that is, Tn


plz give me code of these problems....i am beginner in programing....i felt difficulty in these problems....plz help out
Sep 16, 2013 at 4:57pm
Forum sticky wrote:
Don't post homework questions
Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.


The third task claims that the input is one integer, but the expected output comes from some indexed set. Where did that set came from?
Last edited on Sep 16, 2013 at 5:01pm
Sep 16, 2013 at 5:34pm
plz tell me how i can write the condition of smallest number in while loop
Sep 16, 2013 at 5:39pm
plz plz plz tell the solution of 3rd programm.........only one program plx plx plz....i have already waste the 3 hours at this problem
Sep 16, 2013 at 5:47pm
Post your "3 wasted hours" code ;)
Sep 16, 2013 at 6:20pm
#include <iostream>

using namespace std;

int main ()
{
int n=1,smallest=0;

while ( n>0 )
{
cout<<"Enter a number"<<endl;
cin>> n;
}

smallest=n;

for (int i = n; i > 0 ; i++)
{
if(n>smallest)
smallest=n;
}

cout<< "smallest non-negative number is :" << smallest << endl;

return 0;
}
Sep 16, 2013 at 6:42pm
what is problem in this code??????????
Sep 16, 2013 at 6:45pm
Two major issues are immediate:
1) Your for loop will run forever for any positive n. Did you mean to decrement instead? you could do either for(int i(n); i > 0; --i) or for(int i(1); i < n+1; ++i).
2) Your if condition in the for loop is backwards. If n is smaller (not larger) than the current smallest number, then you assign n to smallest.

Edit:
But the whole code will eventually always say 1 is the answer (if n is any positive number).
Last edited on Sep 16, 2013 at 6:46pm
Sep 16, 2013 at 6:53pm
plz tell solution in code language
Sep 16, 2013 at 7:18pm
plz tell code
Sep 16, 2013 at 7:27pm
closed account (jwkNwA7f)
I understand that you want it, but it is your responsibility to do your own homework. This would be cheating. We are not allowed to do your homework for you. But, if you have any questions about it, we can help you with that.
Last edited on Sep 16, 2013 at 7:28pm
Sep 16, 2013 at 7:39pm
plz plz plz......i have to submit this tommorow......plz plz plz only one code plz plz plz plz plz plz plz plz plz plz
Sep 16, 2013 at 7:46pm
closed account (jwkNwA7f)
We are not going to give you the code for the entire program. But, you can ask questions about each problem.
Sep 16, 2013 at 7:48pm
#include <iostream>

using namespace std;

int main ()
{
int n=1,smallest=0;

while ( n>0 )
{
cout<<"Enter a number"<<endl;
cin>> n;
}

smallest=n;

for (int i = n; i > 0 ; i++)
{
if(n>smallest)
smallest=n;
}

cout<< "smallest non-negative number is :" << smallest << endl;

return 0;
}
Sep 16, 2013 at 7:49pm
there is code......tell me mistake if u r not going to give me code
Sep 16, 2013 at 7:53pm
This is the same code like 1.5 hours ago you did nothing to improve it :(
Sep 16, 2013 at 7:55pm
closed account (jwkNwA7f)
@awais rana Daleth already told you some things to improve it here:
http://www.cplusplus.com/forum/beginner/110874/#msg605414
Sep 16, 2013 at 8:05pm
worst help i have ever seen......but God is there who will do my help from other source
Sep 16, 2013 at 9:38pm
@awais rana don't be rude, with your attitude you will never get help look at your posts
Sep 16, 2013 at 9:47pm
closed account (jwkNwA7f)
+1 for Chriscpp
Pages: 12