another stupid question :S

hey everybody ...as im a starter i tried to create some single scripts first... so i decided to make a program which gets what ever number the user wants and then it calculates the min.
it compiles without any error but its really weird that it calculates the max instead... + idk why there is something wrong with the loop.
could some body help me? :S
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
32
33
34
35
36
#include <iostream.h>
#include <conio.h>

int main()
{
	int a;
	char c;
	int i;
	int min;
	i=1;
	c='y';
	while(c=='y')
	{
		cout<<"Please enter number"<<i<<":";
		cin>>a;
		cout<<"Do you wanna continue?(y,n)";
		c=getche();
		if(c=='y')
		{
			cin>>a;
			if(a>min)
			{
				min==a;
			}
		}
		if(c=='n')
		{
				cout<<"here is the min:"<<a;
				if(a<min)
				{
					min==a;
				}
		i++;
		}
	}
}
If you are trying to calculate the minimum you will want to do
if(a < min not if (a > min)

Also at line 23 you will want to use = not ==.
min = a;

= is used for directly assigning values
== is used to compare 2 variables.

It is also odd that is does a check for the minimum when the user enters in n.
Last edited on
i edited it a lil bit... it works fine when i press y ... but the count system( please press the number "i") doesnt work :( also when i press n it doesnt count the min :S
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
32
33
34
35
36
37
#include <iostream.h>
#include <conio.h>

int main()
{
	int a;
	char c;
	char d;
	int i;
	int min;
	i=1;
	c='y';
	while(c=='y')
	{
		cout<<"Please enter number"<<i+1<<":";
		cin>>a;
		cout<<"Do you wanna continue?(y,n)\n";
		c=getch();
		if(d=='y')
		{
			cin>>a;
			if(a>min)
			{
				min==a;
			}
		}
		if(d=='n')
		{
				cout<<"here is the min:"<<a;
				if(a>min)
				{
					min=a;
				}
		i++;
		}
	}
}
Last edited on
can anybody help? :S
closed account (4izT0pDG)
Here's my take on it.
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
32
33
#include <iostream>

using namespace std;

int main()
{
    char c;
    int a,b,min;
    
    c='y';

    cout<<"Please enter a number: ";
    cin>>a;
    min=a;

    while(c=='y')
   {
       cout<<"\nPlease enter another number: ";
       cin>>a;

	if(c=='y')
	{
	    if(a<min)
	    min=a;
        }

        cout<<"\nDo you wanna continue?(y,n)\n";
        cin>>c;

   }

    cout<<"Here is the minimum: "<<min;
}
I see you're using a very old compiler, from before 1998. This is a bit silly. Get a modern, free compiler.
@ocasio101 : thx :)
@moschops : well this is what we use in class (as begginers in pawn) any modern compiler you suggest? which is kinda near turbo c++? :)
Quit using Turbo C++. It's a very old compiler and if you are studying from a modern book your programs won't compile to be correct even if they are. Use Visual C++ Express (it's free) from Microsoft or use G++ via MinGW or Cygwin.
Yeah, your two main choices are Visual C++ (blurgh) or Code::Blocks (awesomesauce)
Topic archived. No new replies allowed.