To select a laptop for an online class based on a budget below $400
Question
Make a complete observation and analysis for this program.
*Note: I’m using Dev-C++
Problem: To select a laptop for an online class based on a budget below $400.
#include <iostream> using namespace std; int main() { int amount = 1, choice; while (amount !=0) { cout<<"Enter your budget below $400: "; cin>>amount; if(amount <= 400 && amount > 350){ choice = 1; cout<<"\n***Recommendation*"<<endl; }else if(amount<=350 && amount > 300){ choice = 2; cout<<"\n***Recommendation*"<<endl; }else if(amount<=300 && amount > 250){ choice = 3; cout<<"\n***Recommendation*"<<endl; }else if(amount<=250 && amount > 200){ choice = 4; cout<<"\n***Recommendation*"<<endl; }else if(amount <= 200 && amount > 150 ){ choice = 5; cout<<"\n***Recommendation*"<<endl; }else{ cout<<"No recommendation for your budget"; } switch (choice) { case 1: cout<<"Lenovo IdeaPad 3"<<endl; cout<<"CPU: 2.4GHz Intel Pentium 6405U"<<endl; cout<<"RAM: 8GB"<<endl; cout<<"\nPRICE: $355.00"<<endl; break; case 2: cout<<"Dell Inspiron 3583"<<endl; cout<<"CPU: 1.6GHz Intel Celeron"<<endl; cout<<"RAM: 4GB"<<endl; cout<<"\nPRICE: $333.00"<<endl; break; case 3: cout<<"Acer Chromebook Spin 311"<<endl; cout<<"CPU: AMD A4-9120C - Intel Celeron N4000"<<endl; cout<<"RAM: 4GB"<<endl; cout<<"\nPRICE: $279.00"<<endl; break; case 4: cout<<"Lenovo IdeaPad 1 14-inch"<<endl; cout<<"CPU: AMD A4-9120E - A9-9420E"<<endl; cout<<"RAM: 4GB"<<endl; cout<<"\nPRICE: $245.00"<<endl; break; case 5: cout<<"HP Chromebook 11"<<endl; cout<<"CPU: 1.6GHz Intel Celeron N3060"<<endl; cout<<"RAM: 4GB"<<endl; cout<<"\nPRICE: $185.00"<<endl; break; } cout<<"\nPress 0 to exit:"; cin>>amount; } return 0; }
Summary
In this program, the User will enter an amount, and on the basics of that amount, the program will show the output. Amount entered is for the laptop and its features. The program will match the amount entered and laptop its features which matched and On the basics of the amount entered laptop and its features will be printed on the screen.
Explanation of the code:
The program is to select a laptop and its features for an online class on the budget of the user i.e. $400
Inside the main method, two variables are declared naming amount and choice where the amount is assigned a value of 1. A while loop is used where it will run until the amount is not equal to 0. In the loop, the user will be asked to enter an amount each time the loop executes.
- If the user enters an amount from $350 to $400 so choice 1 will get selected and it will show the laptop which has features like:
Name: Lenovo IdeaPad 3
CPU: 2.4GHz Intel Pentium 6405U
RAM: 8GB
PRICE: $355.00
- If the user enters an amount from $300 to $350 so choice 2 will get selected and it will show the laptop which has features like:
Name: Dell Inspiron 3583
CPU: CPU: 1.6GHz Intel Celeron
RAM: 4GB
PRICE: $333.00
- If the user enters an amount from $250 to $300 so choice 3 will get selected and it will show the laptop which has features like:
Name: Acer Chromebook Spin 311
CPU: AMD A4-9120C – Intel Celeron N4000
RAM: 4GB
PRICE: $279.00
- If the user enters an amount from $200 to $250, so choice 4will get selected and it will Name: Lenovo IdeaPad 1 14-inch
CPU: AMD A4-9120E – A9-9420E
RAM: 4GB
PRICE: $245.00
- If the user enters an amount from $150to $200, so choice 5 will get selected and it will show the laptop which has features like:
Name: HP Chromebook 11
CPU: 1.6GHz Intel Celeron N3060
RAM: 4GB
PRICE: $185.00
In case if the user enters the amount 0, then the value of the amount variable will become 0 and the loop will stop executing and will get terminated and as a result, the program will stop executing.
Here users have to make a choice between different laptops for that, a switch statement is used.
Also, read using python regular expressions, write python script.