a problem in compiling a program

hello there
I am studying c++ programming for the first time and i need your help for this code

//This program will be used to determine a posative even value
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int value;
cout<<"Enter a posative integer value:";
cin>>value;
if(value>0)
cout<<"a posative value"<<endl;
else if(value<=0)
cout<<"an error message"<<endl;
if(value%2==0,value>0,value%2==0)
cout<<"Even"<<endl;
else if(value>=100,value>0,value%2==0)
cout<<"Big even"<<endl;
else if(value<100,value>0,value%2==0)
cout<<"Small even"<<endl;
if(! value%2==0,value<=0,value%2==0)
cout<<"odd"<<endl;
else if(value>=100,value>0,value%2==0)
cout<<"Big odd"<<endl;
else if(value<100,value>0,value%2==0)
cout<<"Small odd"<<endl;
else
cout<<"an error message"<<endl;//in case the value is nigative
cout<<"press any key to continue";
while(!kbhit());
}//end function main

when i print out a number ..i have wrong information
for example
number 5..when i input it the output shows it as
big oven-indivisiable which are wrong

can you help me?Thank you




Last edited on
I got your code running there were a few mistakes but that is how we learn

the main mistake in your code was with the if statements

if you use a comma in an if statement it is viewed as an or directive

ie. if (condition1 == true <or> condition2 == true)

what you need is the and directive && as you can see is used in the code below

if (condition1 == true && condition2 == true)

the other problem was with the value%2 == 0 in the Odd number code
if odd you should use either (value%2 != 0 or value%2 == 1 or !value%2 == 00)

hope this helps you with your programming.

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
38
39
40
41
42
43
44
45
46
47
48
#include<conio.h>
using namespace std;

int main()
{
	int value;
	
	cout<<"Enter a posative integer value:";
	cin>>value;

	if(value>0)
		cout<<"a posative value"<<endl;

	else if(value<=0)
		cout<<"an error message"<<endl;

	///
	if(value%2==0 && value>0 && value%2==0)		//value % 2 tested twice
		cout<<"Even"<<endl;

	if(value>=100 && value>0 && value%2==0)		//else if removed because it wont
												// get here unless first if is false
		cout<<"Big even"<<endl;

	else if(value<100 && value>0 && value%2==0)
		cout<<"Small even"<<endl;

	///
	if( ! value%2==0 && value>=0 && value%2==1)  // second value%2=0 should be removed 
												// also changed if value (<=) 0 {negative}
		cout<<"odd"<<endl;

	if(value>=100 && value>0 && value%2==1)		//else if removed same as above.
												//value%2 == 1 if number is odd
		cout<<"Big odd"<<endl;
	
	else if(value<100 && value>0 && value%2==1)	//value%2 == 1 if number is odd
		cout<<"Small odd"<<endl;

	//else									//removed this code as it is done at top of code
	//	cout<<"an error message"<<endl;	//in case the value is nigative

	
	cout<<"press any key to continue";

	while(!kbhit());

}//end function main 
Last edited on
Thank you so much for helping me..
i thought we are not allowed to use && (and)or || (or)in if else if statement...or that what my friend said to me...
thank you for your help again i really appreciate it:)
Your Friend might mean that you are not allowed to use the && for this exercise, id ask and if that is the case you would have to do something like this

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
38
39
40
41
42
43
44
#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
	int value;
	
	cout<<"Enter a posative integer value:";
	cin>>value;

	if(value>0)
	{
		cout<<"a posative value"<<endl;

		if (value%2 == 0)
		{
			cout<<"Even"<<endl;
			
			if (value >= 100)
			{
				cout<<"Big even"<<endl;
			}
			else
			{
				cout<<"Small even"<<endl;
			}
		}
		else
		{
			// do odd <if> calulations here
		}
	}
	else
	{
		cout<<"an error message"<<endl;
	}

	
	cout<<"press any key to continue";

	while(!kbhit());

}


Ive left you some work to do with the odd numbers.
Personaly i think that it is easier to read this way.

ok bye
Shredded
Yeah that's right..
our Mr told us that it's not allowed to use || (maybe it is allowed but he didn't want us to learn about it because we can do it in easier functions)..but you know when i saw ur code the following one :
value<100 && value>0 && value%2==1

much bigger than my level:D..That's ok:) i'm going to do odd numbers..and i had so many question about it..because i haven't seen it during my studies..It's right for sure but i prefer the socend one becuase it's more sensible to me..according to what i have learned
That's ok:) i'm going to do odd numbers..But really for me as a biggner i feel sometimes lost..one mistake and you lose everything
anyway...Thank you so much ... have a nice day
Last edited on
Topic archived. No new replies allowed.