Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.4 kB
7
Indexable
Never
#include <iostream>
using namespace std;
const int MinGrade = 56;

int main()
{
    int number = 0;
    cout << "Enter your choise 1-3:\n";
    cin >> number;
   int num, digit, count = 0;
    switch (number)
    {
        case 1:
            char TAV;
            int Assci;
            cout << "Enter your char:\n";
            cin >> TAV;
            Assci = (int)TAV;
            if (TAV > '@' && TAV < '[' || TAV>'`' && TAV < '{')
            {
                if (Assci > '@' && Assci < '{')
                {
                    if (TAV < '[')
                    {
                        Assci = Assci + ' ';
                        cout << "the char is:" << (char)Assci;
                    }

                }
                if (TAV >= '[')
                {
                    Assci = TAV - ' ';
                    cout << "the char is:" << (char)Assci;
                }
            }

            else
                cout << "the char is:" << (char)Assci;

            break;

        case 2:

            //int num, digit, count = 0;
            cout << "Enter a number:\n";
            cin >> num;

            if ((num < -9999) || (num > -1000 && num < 1000) || (num > 9999))
            {
                cout << "Error!\n";
            }

            num = abs(num);

            cout << "Enter a digit:\n";
            cin >> digit;
            if (digit > 9 || digit <= -9)
            {
                cout << "Error!\n";
            }

            if (num % 10 == digit)
            {
                count += 1;
            }

            num /= 10;

            if (num % 10 == digit)
            {
                count += 1;
            }

            num /= 10;

            if (num % 10 == digit)
            {
                count += 1;
            }

            num /= 10;

            if (num % 10 == digit)
            {
                count += 1;
            }

            cout << "the number appears:" << count << " times";

            break;

        case 3:

            double grade1, grade2, grade3;
            cout << "Enter your 3 grades:\n";
            cin >> grade1 >> grade2 >> grade3;

            if (grade1 < MinGrade && grade2 < MinGrade && grade3 < MinGrade)
            {
                cout << "Failed!\n";
            }

            if (grade1 >= MinGrade && grade2 >= MinGrade && grade3 >= MinGrade)
            {
                cout << "The average is:\n" << (grade1 + grade2 + grade3) / 3;
            }

            if (grade1 >= MinGrade && grade2 >= MinGrade && grade3 < MinGrade)
            {
                cout << "The average is:\n" << (grade1 + grade2) / 2;
            }

            if (grade1 < MinGrade && grade2 >= MinGrade && grade3 >= MinGrade)
            {
                cout << "The average is:\n" << (grade2 + grade3) / 2;
            }

            if (grade1 >= MinGrade && grade2 < MinGrade && grade3 >= MinGrade)
            {
                cout << "The average is:\n" << (grade1 + grade3) / 2;
            }

            else
            {
                if (grade1 >= MinGrade)
                    cout << "The average is:\n" << grade1;

                if (grade2 >= MinGrade)
                    cout << "The average is:\n" << grade2;

                if (grade3 >= MinGrade)
                    cout << "The average is:\n" << grade3;
            }
            break;

        default:
            cout<<"Error, try again!\n";

    }
}