So my first question is about IF function
int number;
cin>>number;
if (number>99999){
cout<<"Your number has more than 5 digits"<<endl;
return number;}
else if (number<9999){
cout<<"Your number has less than 5 digits"<<endl;
return number;}
else if (number=0){
cout<<"You entered 0... Exiting program"<<endl;
return 0;}
else
My first problem is when i type 0 it doesn't says "You entered 0... Exiting program", but it says "Your number has less than 5 digits". Ive tried to put !0 in else if like "else if (number<9999 && !0)" but that doesn't work.So if anybody could give me a hint it would be nice.
My second problem is that "return number;" doesn't put me back to "int number;" i know i am wrong with this but could someone tell me how it is done. Ty
// Test - Simple program to test.
#include <cstdio>
#include <cstdlib>
#include <iostream>
usingnamespace std;
int test()
{
int number;
cout << "Please, give me a number: ";
cin >> number;
if (number>99999)
{
cout << "Your number has more than 5 digits\n" << endl;
return number;
}
elseif (number == 0)
{
cout << "You entered 0... Exiting program\n" << endl;
return number;
}
else
{
cout << "Your number has less than 5 digits\n" << endl;
return number;
}
}
int main(int NumberofArgs, char* pszArgs[])
{
int num;
num = test();
cout << "The number is: " << num << "\n";
// wait until user is ready before terminating program
// to alow the user to see the program results
system("PAUSE");
return 0;
}
// Test - Simple program to test.
#include <cstdio>
#include <cstdlib>
#include <iostream>
usingnamespace std;
int giveme()
{
int number = 0;
cout << "Please, give me a number: ";
cin >> number;
return number;
}
int main(int NumberofArgs, char* pszArgs[])
{
int num;
num = giveme();
cout << "The number is: " << num << "\n";
while (num != 0)
{
if (num > 99999)
{
cout << "Your number has more than 5 digits\n" << endl;
num = giveme();
}
else
{
cout << "Your number has less than 5 digits\n" << endl;
num = giveme();
}
}
cout << "You entered 0... Exiting program\n" << endl;
// wait until user is ready before terminating program
// to alow the user to see the program results
system("PAUSE");
return 0;
}
sorry if i made it a little understandable it's because i have stumbled upon a problem at that point... so i didn't continue. From here program continues to accept 5 digit numbers until u type 0, and from that point program writes how many 5'ves occur in that 5 digit number per entry... But yeah that helped a lot.
Oh... forgot i had one more question... Why doesn't the return function brings me to "int number; " (to the beginning so i can enter numbers until i press 0) as i wrote "return number;"
I have one more question... is it somehow possible to do this with IF function (i've tried this way but it gives me an error)or maybe there is an better way to do this
(x,y,z are just for example)
IF (x=5 || y=5 || z=5)
cout<<"test";
else
cout<<"test2";