Logical Operators + Ifs Small Problems

Pages: 12
closed account (oG8qGNh0)
Write your question here.

[code]PROBLEM #4
In college, each class typically counts as somewhere between 3 and 5 credits.

A student must take at least 12 credits to be considered full time. Otherwise, they are considered part time. This status often affects scholarships. Students are allowed to take a maximum of 1 credits per semester.

At UMCP, resident students (those whose parents live in the same state as the school) pay $360 per credit. If they take so many credits that the calculated total is more than the cap, which is $5,389.50, then they only pay $5,389.50 for the semester.

Nonresident students (those from other states) pay $1387 per credit with a maximum tuition fee capped at $18,445.50 for the semester.

Prompt the user for the student's number of credits and residency status (N or R), and then output that student's status (part or full time) and total tuition owed.

Print appropriate error messages if the input is a negative number or greater than 17. Please ensure that monetary amounts look like money when you print (i.e. format to 2 decimal places).

Example Output:
Number Credits: 6
Resident(R)/Non-Resident(N): R
Student is: Part Time
Tuition is: $2160.00

I honestly have no idea on how to do this
> Students are allowed to take a maximum of 1 credits per semester.
¿ah? ¿how may you reach the 12 credits then? ¿or how may you ever complete a class that requires you 3 credits?

> resident students pay $360 per credit
> Nonresident students pay $1387 per credit
¿so apart from rent they have to pay credits at 400% the price? ¿what's the logic behind that?
1
2
3
4
double tuition( char status, int C )
{
    return ( status == 'R' ) * min( 360.0 * C, 5389.5 ) + ( status == 'N' ) * min( 1387.0 * C, 18445.5 );
}
Last edited on
What part are you having trouble with? What have you got so far? Can you display the required prompts and obtain input? Post what you have so far.
closed account (oG8qGNh0)
this is my first day in AP Computer Programming. I had to switch classes. so honestly i have no idea how to get started
How much of C++ do you know? Do you know about variables, assignment, main(), cin, cout?

Does this make sense:

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main()
{
    double num {}; 

    std::cout << "Enter a number: ";
    std::cin >> num;

    std::cout << "You entered " << num << std::endl;
}


If this doesn't make sense, have you done any programming at all in any language?

this is my first day in AP Computer Programming.

A good online tutorial could help. Learn C++ is one of the best in English: https://www.learncpp.com/
> i have no idea how to get started
try to solve it yourself with pen and paper
write pseudocode
draw a flow diagram
I advise you to use integers for money. If there are any actual cent values in play, use 1 = 1 cent instead of 1 = 1 dollar. If there are not any cents in play, use 1 = 1 dollar and add ".00" where necessary as text on print statements.
If you use a floating point for money, you may get small rounding errors that take some knowledge to avoid.

until you clarify the 1 credit hour max / semester, the question is not really doable.
Last edited on
closed account (oG8qGNh0)
funny thing, um i dont know a thing about c++ but thanks for the link furry guy!

I have just been learning about python and java. Never about c++
java is very similar to c++. Much of what you know there translates, but c++ does not require a bogus class when no object is needed, and does not require you to name your files THEIR way, and supports unsigned variables and many more low level things that java threw out to be portable.

python is its own special thing. Its a throwback to the 1950s where your indents affect the code, like they did on punch cards. That alone kills it for me, but its a good language for a hobby programmer that wants to get stuff done without any fuss.
Last edited on
closed account (oG8qGNh0)
#include<iostream>
using namespace std;
int main()
{
double tuition;
char status;
int C;
return ( status == 'R' ) * min( 360.0 * C, 5389.5 ) + ( status == 'N')* min( 1387.0 * C, 18445.5 );
std::cout << "Number credits: \n";
std::cout << "R or N?: \n";
std::cout << "Student is: \n";
std::cout << "Tuition is: \n";
}

All I have so far. Anything wrong?
closed account (oG8qGNh0)
changed it up a bit to:

#include<iostream>
using namespace std;
int main()
{
double tuition;
char status;
int c;
return ( status == 'R' ) * min( 360.0 * c, 5389.5 ) + ( status == 'N')* min( 1387.0 * c, 18445.5 );
cout << "Number credits: \n";
cin >> c;
cout << "Resident or non-resident: \n";
cin >> status;
cout << "Student is full time or part time: \n";
cin >> status;
cout << "Tuition is: \n";
cin >> tuition;
}
closed account (oG8qGNh0)
don't know what's wrong and why the output doesnt say anything... any suggestions?
What are you trying to accomplish with that return statement?

And perhaps you may want to look at some documentation for "return":

https://docs.microsoft.com/en-us/cpp/c-language/return-statement-c?view=vs-2019

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    char status;
    int c;

    cout << "Number credits: ";
    cin >> c;
    cout << "Resident or non-resident (R/N): ";
    cin >> status;

    if (c < 12)
        cout << "Part time\n";
    else
        cout << "Full time\n";

    cout << "Tuition is: " << ( status == 'R' ) * min( 360.0 * c, 5389.5 ) + ( status == 'N')* min( 1387.0 * c, 18445.5 );
} 


This uses lastchance's calculation from above - which is probably more 'compact' than expected. It relies upon the result of an equality test (==) being either true (value 1) or false (value 0). Anything multiplied by 0 is 0 and adding 0 to anything doesn't change its value.

You'll need to do the formatting as required to 2 decimal places.
Last edited on
closed account (oG8qGNh0)
Hmmm. thanks. How long have you done computers programming?
Over 35 years.......
Last edited on
closed account (oG8qGNh0)
thanks! so even though i know you did not finish it,

I added

cout <<"Part time or full time: ";
cin >> status
after the cin >> status;

was i supposed to add that ?
No. That's not an input requirement. That is determined by the program based upon the number of credits entered. Re the spec from your first post. For full time the number of credits must be at least 12.

1
2
3
4
if (c < 12)
        cout << "Part time\n";
    else
        cout << "Full time\n";


Pages: 12