# Cos1511_Assignment 2-r.docx - Assignment 2 Question 1a...

• Homework Help
• 17
• 100% (3) 3 out of 3 people found this document helpful

This preview shows page 1 - 5 out of 17 pages.

Assignment 2 Question 1a while (age != 0) { if((age < 30) && (finalMark > 65)) { cout << "The candidate qualifies ." << endl; break; } else { cout <<endl; cout << "The candidate do not qualify ." << endl; cout << "-----------------------------------------------------"<<endl; cout << "Enter the age and final mark ." << endl; cin>> age ; cin>> finalMark ;} } Question 1b CODE OUTPUT a for (int i = 1; i <= 1; i++) cout << ”*”; cout << endl; * b for (int i = 2; i >= 2; i++) cout <<”*”; cout << endl; Endless loop *********************** c for (int i = 1; i <= 1; i--) cout << “*”; Endless loop *********************** d for (int = 12; i >= 9; i--) cout << “*”; cout << endl; Error ‘i’ was not declared e for (int i = 0; i <= 5; i++) cout << “*”; cout << endl; ****** f for (int i = 1; i <= 5; i++) cout << “*”; i = i + 1; cout << endl; error: name lookup of 'i' changed for ISO 'for' scoping Question 1c int main()
{ int x , n = 10 , i = 0; while(i <= n) {if (i < 5 && i != 2) cout << 'X'; i++; } return 0; } Question 1d #include <iostream> using namespace std; int main () { float counter; int number; int zeros; int odds; int evens; int LIMIT = 10; cout << "Please enter " << LIMIT << " integers, " << "positive, negative, or zeros." << endl; cout << "The numbers you entered are:" << endl; for (int counter = 1; counter <= LIMIT; counter++) { cin >> number; switch (number / 2) { case 0: evens++; if (number = 0) zeros++;
case 1: case -1: odds++; } } cout << endl; cout << "There are " << evens << " evens, " << "which includes " << zeros << " zeros." << endl; cout << "The number of odd numbers is: " << odds << endl; return 0; } Question 2a #include <iostream> using namespace std; int main() { float cost ,TotalDiscount , TotalTax ,TotalBill ,cash; float NumberOfRooms , NumberOfDays ; float Tax = 0.10 ; int chooseNUMBER , Discount; cout<< "Please enter the following:"<<endl; cout<<""<<endl; cout<< "cost per room: R "; cin >> cost ; cout<< "sales tax per room: "<<Tax*100<<endl;
cout<< "the number of rooms: "; cin >> NumberOfRooms ; cout<< "number of days: "; cin >> NumberOfDays ; cout<<""<<endl; cout<<"if the rooms are less than 10...press 0 .... if more than 10..press 1."<<endl; cout<<"..if more than 20...press 2...if more than 30..press 3 ........ "<<endl; cin>>chooseNUMBER; cash = (cost*NumberOfRooms)*NumberOfDays ; switch(chooseNUMBER) { case 1 : Discount = 10 ; TotalDiscount = cash*0.10; break ; case 2 : Discount = 20 ; TotalDiscount = cash*0.20; break ; case 3 : Discount = 30 ; TotalDiscount = cash*0.30; break ; default : cout <<"No dicount" ; break; } cout<<""<<endl; while(NumberOfDays >= 3 ) { TotalDiscount +=cash*0.05 ; cout<<"Additional discount is R "<<TotalDiscount<<endl; break; } cout<< "The total cost for one room is "<<cost<<endl; cout<< "The discount per room is "<< Discount <<"%"<<endl; cout<< "The number of rooms booked: "<<NumberOfRooms<<endl; TotalBill=cash-TotalDiscount; TotalTax = TotalBill*Tax ;