Algorithms and Programming Lab Lesson 2

beykent logo ile ilgili görsel sonucu
Question 1:
Suppose savings and expenses are variables of type double that have been given values.Write an if-else statement that outputs the word Solvent, decreases the value of savings by the value of expenses, and sets the value of expenses to 0, provided that savings is at least as large as expenses .If,however, savings is less that expenses , the if -else statements simply outputs the word  Bankrupt and does not change the value of any variables.

codes are here:
#include <iostream>
#include <iomanip>

using namespace std;
//soru 22


int main(){

double expenses,savings,total;

   cout <<"Enter the expenses and savings\n"<< endl;
   cin >> expenses >> savings;
   total = savings - expenses;

if(total<0){
   cout<<"Bankrupt\t"<< expenses <<"\t"<< savings << endl;

}
 
else{
    savings = savings - expenses;
    expenses =0;
    cout <<"Solvent"<<"\t" << savings;
}


}

Question 2:
Write and if-else statement that outputs the word Passed provided the value of the variable exam is greater than or equal to 60 and the value of the variable programs_done is greater than or equal to 10.Otherwise, the if-else statement outputs the word Failed.The variables exam and programs_done are both type int.

Answer 2:
#include <iostream>
#include <iomanip>

using namespace std;
//soru 23


int main() {
int exam;
cout <<"Enter your result\n"<<endl;
cin >> exam;
if(60<= exam){

cout << "Passed"<< endl;

}
else if(10 <= exam < 60){
    cout <<"programs_done"<< endl;
}
else{
cout <<"Failed" ;
}



return 0;

}

Comments

Popular Posts