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

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

View Full Document Right Arrow Icon
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()
Image of page 1

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

View Full Document Right Arrow Icon
{ 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++;
Image of page 2
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;
Image of page 3

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

View Full Document Right Arrow Icon
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 ;
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern