C++ problem | Sololearn: Learn to code for FREE!

-1

C++ problem

How can I make a limitation for a variable I want to declare that for example 100< i=<1000

4/12/2021 5:17:12 PM

Sahaarr

18 Answers

New Answer

+3

Not sure what do you mean, but this is what I did: https://code.sololearn.com/cZZnKQ7abQ9U/?ref=app

+2

Maher Al Dayekh Thank you for answering!🙏🏼

+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

https://code.sololearn.com/cIPBZyDUlF72/?ref=app Use the above code ro get greater than 100 lesser than 1000 Simple code friend

+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

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

-1

Remove errors