+ 2
C++ problem
How can I make a limitation for a variable I want to declare that for example 100< i=<1000
20 Answers
+ 4
Not sure what do you mean, but this is what I did:
https://code.sololearn.com/cZZnKQ7abQ9U/?ref=app
+ 4
Maher Al Dayekh Thank you for answering!🙏🏼
+ 3
https://code.sololearn.com/cIPBZyDUlF72/?ref=app
Use the above code ro get greater than 100 lesser than 1000
Simple code friend
+ 2
In addition, if you care about your memory usage, you can use bitfields, which are explained here:
https://en.cppreference.com/w/cpp/language/bit_field
What's more, if you are sure about limits, and you're sure it will never be negative, you can use unsigned type.
You can also learn about data structure alignment (e.g memory padding and packing). At least if you want to know something more about how memory works
+ 1
Coder Kitten Thank you!
+ 1
For limitation use this code
https://code.sololearn.com/coxQMtmUxdpH/?ref=app
+ 1
In an if-statement?
https://code.sololearn.com/cDKOUNe2sYyU/?ref=app
+ 1
#include<iostream>
using namsspace std;
Int main() {
int crabs;
int trio;
cim >> crabs;
Trio = crabs/3;
cout << Trio;
return 0;
}
Average word :-
https://www.sololearn.com/discuss/2875277/?ref=app
+ 1
Use AND operator (&&):
i>100&&i<=1000
0
Coder Kitten I want to define i as variable that ranges from 100 to 1000
Should I use cmath or other libraries?
0
Sahaarr is the code available for you, or something is wrong?
0
Maher Al Dayekh I'm actually solving a question, At first I used i in main function in a "for"
Then I wanted to use it again in another function, but I don't know how to define i's limitation in that function :(
0
#include <iostream> using namespace std; int main() { int crabs; int Trio; cin >> crabs; Trio = crabs/3; cout << Trio; return 0; }
0
#include<iostream>
using namsspace std;
Int main() {
int crabs;
int trio;
cim >> crabs;
Trio = crabs/3;
cout << Trio;
return 0;
}
Average word :-
https://www.sololearn.com/discuss/2875277/?ref=app
0
#include <iostream>
using namespace std;
void calutale equation on result ( float a, float b, float c, float d, float x );
void max result ( float sp1, float sp2, float sp3 );
main()
{
char sp;
calculate equation result\( 2, 3, 4, 5, 10 );
do
cout<<"\n do you to enter more data (y for yes n for no) : " ;
cin>> sp;
if (sp=='y' || sp=='y')
calulate equation on result (6, 7, 8, 9, 11 );
else
break;
} while ( sp=='y' || sp=='y' )
}
void calulate equation on result ( float a, float b, float c, float d, float x)
{
float sp1, float sp2, float sp3;
sp1= x+b/ (3*a);
sp2=(3*a*c-(b*b)) / ( 3* (a*a));
sp3=( 2*( b*b*b)-9* (a+b+c)+27* (a*a) *d) /
cout<<" spot 1: "<< sp1 <<endl;
cout<<" spot 2: "<< sp2 <<endl;
cout<<" spot 3: "<< sp3 <<endl;
max result ( sp1, sp2, sp3 ); // function call
}
void max result ( float sp1, float sp2, float sp3 )
{
if (sp1 > sp 2 && sp1 > sp3 )
cout <<"\ spot 1 result is maxium";
else if ( sp2> sp1 && sp2 > sp3)
cout <<"\ spot 2 result is maxium";
else
cout <<"\ spot 3 result
0
Write a c++ script for students result computation that accepts entries from a user for Student's name, Matriculation number, Department, Course Code, Level, Class Test, Class Assignment, Exam score, Total score, Grade. For the grade, use just 3 categories: >69 = A 45 to 69 = P <45 = F The program should be able to take in scores for different courses and output the result sheet after execution.
0
Write a c++ script for students result computation that accepts entries from a user for Student's name, Matriculation number, Department, Course Code, Level, Class Test, Class Assignment, Exam score, Total score, Grade. For the grade, use just 3 categories: >69 = A 45 to 69 = P <45 = F The program should be able to take in scores for different courses and output the result sheet after execution.
0
You can set the limit of i by making a condition if-else, with logical operator
example:-
if(i>100 && i<=1000)
{
statement1;
}
else
{
statement2;
}
0
C++ question & answers
- 1
Remove errors