0
anyone help with c++ programing for odd and even number where the program prompts the user to enter a guess and report the guess
5 Antworten
+ 4
Your are assigning value instead of comparing in both if statements
Change =(assignment operators) to ==(comparators) in both cases
+ 1
Can you show us your attempt?
+ 1
iostream>
#include <cstdlib>
using namespace std;
int main(){
int randomnumber;
int n,even,odd;
cout << "the random integer is\n";
randomnumber =(rand()%100);
cout << randomnumber <<endl;
cout << "is the number odd or even??\n";
even=( randomnumber % 2 == 0);
odd=(randomnumber % 2!= 0);
cin >>n;
switch(n) {
case 1:
if (n=even){
cout<<" correct\n";
}
else{
cout << " incorrect\n";
}
break;
case 2:
if (n=odd){
cout << " correct\n";
}
return 0;
+ 1
#include <iostream>
using namespace std;
int main() {
int num;
cin>>num;
if(num%2==0 && num>0)
{
cout<<"even"<<endl;
}
else if(num%2==1)
{
cout<<"odd"<<endl;
}
else
{
cout<<0;
}
return 0;
}
0
the user must guess weather the number is even or odd number