//Dr. Ramsey's solutions to the practical questions. 
//there may be bugs or errors present, but should match the practical
//questions given. There ARE other solutions to these problems, but there
//are also incorrect solutions. 
#include <iostream>
#include <string>
using namespace std;

int main() {
  

  //1
  cout << "ops and vars" << endl;
  float fst, sec;
  cout << "Give me two numbers: ";
  cin >> fst >> sec;
  cout << 3 * fst - sec / 2 << endl;

  //2
  float length, width;
  cout << "Give me length and width: ";
  cin >> length >> width;
  cout << "Area of the rect is: " << length * width << endl;

  //3
  string first, second;
  cout << "Give me two strings: ";
  cin >> first >> second;
  if (first == second) {
    cout << "Equal!" << endl;
  }
  else {
    cout << "NOT!" << endl;
  }


  //4
  cout << "conditions" << endl;
  char mychar;
  cout << "give me char: ";
  cin >> mychar;
  if (mychar == 'y' || mychar == 'Y') {
    cout << "you entered y or Y" << endl;
  }
  else {
    cout << " You gave me something else..." << endl;
  }


  //5
  float bill;
  cout << "Give me your dinner bill: ";
  cin >> bill;
  while (cin.fail() || bill < 0 || bill > 200) { //question really asks for an if here
    cout << "something with bad with the input";
    cin.clear();
    cin.ignore(1000, '\n');
    cout << " try again? a bill: ";
    cin >> bill;
  }


  //6
  int op1, op2, operation;
  cout << "enter two ints and then the operation as an int: ";
  cin >> op1 >> op2 >> operation;
  if (operation == 0) {
    cout << op1 + op2 << endl;
  }
  else if (operation == 1) {
    cout << op1 - op2 << endl;
  }
  else if (operation == 2) {
    cout << op1 * op2 << endl;
  }
  else if (operation == 3) {
    cout << op1 / op2 << endl;
  }
  else {
    cout << op1 % op2 << endl;
  }


  //7
  cout << "loops" << endl;
  int nEvens;
  cout << "how many even numbers: ";
  cin >> nEvens;
  for (int i = 0; i < nEvens; i++) {
    cout << i*2+2 << " ";
  }
  cout << endl;


  //8
  int dimension;
  cout << "how big a box of asterisks: ";
  cin >> dimension;
  for (int i = 0; i < dimension; i++) {
    for (int j = 0; j < dimension; j++) {
      cout << "*";
    }
    cout << endl;
  }


  //9
  float totalSum = 0; // a float to avoid int arithmetic
  int numVals;
  cout << "how many values do you wanna average? ";
  cin >> numVals;
  for (int i = 0; i < numVals; i++) {
    cout << "input an integer number: ";
    int x;
    cin >> x;
    totalSum = totalSum + x;
  }
  cout << " The average is: " << totalSum / numVals << endl; //be careful with int arithmetic here
}
