+ 2

C++ problem

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

12th Apr 2021, 5:17 PM
Sahaarr
Sahaarr - avatar
26 Respostas
+ 4
Not sure what do you mean, but this is what I did: https://code.sololearn.com/cZZnKQ7abQ9U/?ref=app
12th Apr 2021, 6:32 PM
Maher Al Dayekh
Maher Al Dayekh - avatar
+ 4
Maher Al Dayekh Thank you for answering!šŸ™šŸ¼
12th Apr 2021, 6:35 PM
Sahaarr
Sahaarr - avatar
+ 3
https://code.sololearn.com/cIPBZyDUlF72/?ref=app Use the above code ro get greater than 100 lesser than 1000 Simple code friend
2nd May 2021, 3:49 PM
Nagesha
Nagesha - avatar
+ 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
12th Apr 2021, 10:29 PM
Michal Doruch
+ 2
Use AND operator (&&): i>100&&i<=1000
15th Jun 2024, 8:12 AM
Felicia Tania
Felicia Tania - avatar
+ 1
Coder Kitten Thank you!
12th Apr 2021, 5:40 PM
Sahaarr
Sahaarr - avatar
+ 1
2nd May 2021, 4:00 PM
Nagesha
Nagesha - avatar
3rd May 2021, 9:03 PM
Nicholas
Nicholas - avatar
+ 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
7th Sep 2021, 5:47 PM
Shubham Bhatia
Shubham Bhatia - avatar
0
Coder Kitten I want to define i as variable that ranges from 100 to 1000 Should I use cmath or other libraries?
12th Apr 2021, 5:31 PM
Sahaarr
Sahaarr - avatar
0
Sahaarr is the code available for you, or something is wrong?
12th Apr 2021, 6:37 PM
Maher Al Dayekh
Maher Al Dayekh - avatar
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 :(
12th Apr 2021, 6:40 PM
Sahaarr
Sahaarr - avatar
0
#include <iostream> using namespace std; int main() { int crabs; int Trio; cin >> crabs; Trio = crabs/3; cout << Trio; return 0; }
6th Sep 2021, 1:45 PM
NJOGU NJOROGE
NJOGU NJOROGE - avatar
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
25th Jan 2022, 5:56 AM
Islomiddin Ismoilov
Islomiddin Ismoilov - avatar
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
10th Jun 2022, 7:25 PM
Ali Hamza
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.
27th Oct 2022, 8:06 AM
Haruna Olumide
Haruna Olumide - avatar
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.
27th Oct 2022, 8:07 AM
Haruna Olumide
Haruna Olumide - avatar
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; }
2nd Jan 2023, 10:59 PM
Praveen Sehgal
Praveen Sehgal - avatar
0
C++ question & answers
28th Oct 2023, 11:35 AM
ubaid pasha
ubaid pasha - avatar
0
#include <iostream> using namespace std; int main() { int num1 = 100; int num2 = 1000; for(int i = 100; i<=num2; i++ ){ std::cout << "[ "<< i << " ]" << std::endl; } return 0; }
3rd Dec 2024, 1:27 PM
Giorgi Tsertsvadze
Giorgi Tsertsvadze - avatar