Cos1511_Assignment 2-r.docx

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

This preview shows pages 1–5. Sign up to view the full content.

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()

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
{ 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;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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 ;
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern