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
#include<conio.h>
usingnamespace std;
int main()
{
int value;
cout<<"Enter a posative integer value:";
cin>>value;
if(value>0)
cout<<"a posative value"<<endl;
elseif(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;
elseif(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;
elseif(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
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
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