#include<iostream>
#include<cstdlib>//for exit
usingnamespace std;
int main()
{
int n;
cout << "enter a number" << endl;
cin >> n ;
if (n>=0 && n <=9)
{cout << "single digit" << endl;
exit(1);
}
if (n>=10 && n<=99);
{cout << "double digit" << endl;
exit(1);}
if (n>=100);
cout << "multi" << endl;
return 0;// int returns value to check if the program has executed correctly,
//but you can do with void main() also if you are allowed
}
#include<iostream>
usingnamespace std;
int main()
{
int n;
cout << "enter a number" << endl;
cin >> n ;
if (n>=0 && n <=9)
cout << "single digit" << endl;
elseif (n>=10 && n<=99)
cout << "double digit" << endl;
elseif (n>=100)
cout << "multi" << endl;
return 0;// int returns value to check if the program has executed correctly,
//but you can do with void main() also if you are allowed in classes
}
For your second problem just do it like the firs one with if statements asking for example
I did it, thank you. For the second one it doesn't gives the correct
answers, it states always "right" whatever number i enter. What can be the problem?
#include <iostream>
using namespace std;
int main()
{
int alfa;
cout << "Enter the angle " << endl;
cin >> alfa;
#include <iostream>
usingnamespace std;
int main()
{
int alfa;
cout << "Enter the angle " << endl;
cin >> alfa;
if (alfa==0)// in if statement == this is if two operands are equal
cout << "Angle 0 " << endl;//when you have one line after if you do not need brackets
elseif (alfa>=1 && alfa <=89)
cout<<"Sharp " << endl;
elseif (alfa==90)//Here you had mistake
cout << "Right" << endl;
elseif (alfa>=91 && alfa <=179)
cout << "Bad" << endl;
elseif (alfa==180)//Here you had mistake
cout << "Flat" << endl;
elseif (alfa==360)//Here you had mistake
cout << "Full" << endl;
else
cout << "Entered not possible value" << endl;
return 0;
}
$ g++ -Wall foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:10:11: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
if (alfa=0)
^
foo.cpp:18:17: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
elseif (alfa=90)
^
foo.cpp:27:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
elseif (alfa=180)
^
foo.cpp:32:18: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
elseif (alfa=360)
^