Make a complete observation and analysis for this program based on a given budget.

QUESTION

Make a complete observation and analysis for this program based on a given budget. Thank you

*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

The user enters an amount and a choice is made to buy a laptop based on this cost and its feature. Based on the price, the affordable laptop details will be printed as the output to the console.

 

EXPLANATION

Analysis of the code:

The given program’s problem statement is to select a laptop for an online class on a specific budget (below $400).

Variables named choice and amount are declared and the variable amount is set to 1. A while loop is made to run until the variable ‘amount’ becomes zero. Inside this while loop, the user is asked to enter an amount of their choice for each iteration. 

 

a) If the user enters an amount which is between $350 and $400, then the recommended laptop has the following features:

Name: Lenovo IdeaPad 3

CPU: 2.4GHz Intel Pentium 6405U

RAM: 8GB

PRICE: $355.00

 

b) If the user enters an amount which is between $300 and $350, then the recommended laptop has the following features:

Name: Dell Inspiron 3583

CPU: CPU: 1.6GHz Intel Celeron

RAM: 4GB

PRICE: $333.00

 

c) If the user enters an amount which is between $250 and $300, then the recommended laptop has the following features:

Name: Acer Chromebook Spin 311

CPU: AMD A4-9120C – Intel Celeron N4000

RAM: 4GB

PRICE: $279.00

 

d) If the user enters an amount which is between $200 and $250, then the recommended laptop has the following features:

Name: Lenovo IdeaPad 1 14-inch

CPU: AMD A4-9120E – A9-9420E

RAM: 4GB

PRICE: $245.00

 

e) If the user enters an amount which is between $150 and $200, then the recommended laptop has the following features:

Name: HP Chromebook 11

CPU: 1.6GHz Intel Celeron N3060

RAM: 4GB

PRICE: $185.00

 

f) If the user enters 0 as the input, then the amount would be considered zero and therefore loop will stop iterating and the program terminates.

 

To implement all six cases, a switch case is used.

 

Also Read: Design a TestScores class that has member variables to hold three test scores

 

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *