hello,
i have some simple questions but i don't know why my code is not correct
see these questons:
1-Write an algorithm to accept three numbers and display the largest one?
this is my code
int num1,num2,num3;
cout <<"Please enter three numbers:";
cin >> num1 >> num2 >> num3;
if(num1 > num2 && num3){
cout <<"The largest number is: " << num1;
}else if(num2 > num1 && num3){
cout <<"The largest number is: " << num2;
}else{
cout <<"The largest number is: " << num3;
}
why this code doesn't wrok correctly???? :(
it made me angry :@ because if i'm the compiler then i can understand the code
i tried also this code to accept four numbers
#include <iostream>
using namespace std;
int main()
{
int num1,num2,num3,num4,largest;
cout <<"Please enter four numbers:";
cin >> num1 >> num2 >> num3 >> num4;
largest = num1;
if(num2 > num1)
largest = num2;
if(num3 > num2)
largest = num3;
if(num4 > num3)
largest = num4;
cout <<"The largest number is: " << largest;
return 0;
}
please try this input 8,5,6,4 >> the output will be 6!!!
please tell me whats the wrong
****
2- accept a number and display all the numbers from 0 to the number entered. Then modify the flowchart so that it displays only odd numbers.
e.g. Given 10, it should output: 1 3 5 7 9
this is my code
int num,count = 1;
cout<<"Please enter a number: ";
cin >> num;
while(count > num){
cout << " "<< num;
num = num + 2;
}
cout <<"end";
return 0;
}
why this one doesn't work?
waiting for you