
01-Dec-2008, 21:33
|
|
New Member
|
|
Join Date: Dec 2008
Posts: 1
|
|
|
I could use some help
Hey all! So I'm taking a Computer Science course at my college and it was going pretty easy for the most part.. until our professor threw us a curve ball. I have to write 6 programs by Wednesday that go a little bit beyond what we learned and I'm have quite some time figuring it out. Of course, don't feel obligated to answer all of these questions but if you offer any help and advice I will be very, very grateful.
- So I got the first program no problem, that wants me to check whether or not a user specified number is prime or not, and why.
But I also need to write one that lists prime numbers to a user specified range. (1-100) Well it prints out the numbers... but not to the range. I understand that the "range <= 100" thing controls the range, but how do I specifiy it with a cin command? Also, how can I get it to not show the numbers that are not prime and only the numbers that are? This is from the model that my teacher gave me to start from but when I remove the stuff about the number not being prime it doesn't work altogether. Here's my code for the program right now.
#include <iostream.h>
void main()
{
int the_number;
int d;
int range;
bool isPrime; // true/false
d = 3; // the dividor
cout << "Enter a range of numbers. (1-100) I'll pick out the numbers that are prime. " << endl;
cin >> range;
for(the_number = 2; range <= 100; the_number++)
{
isPrime = true;
for(d = 2; d <= the_number/2; d++)
{
// check with d (dividor)
if(the_number % d == 0)
{
cout << " " << the_number << " is NOT a prime number because ";
cout << "the number is divisible at least by " << d << endl;
isPrime = false;
break; // breaks out of the inner loop
}
else
{
// cout << "the number is not divisible by " << d << endl;
}
} // end of the for-loop
if(isPrime == true) cout << the_number << " is a prime number, not divisible by any number" << endl;
}
return;
}
- I also have to write a program to find all the solutions numerically within the domains given, for these three questions.
a) 2sin(x^2) = x - 0.5 [-5, 5]
b) ln(x) = -2x + 5cos(x) [0, 10]
c) 3x^2 + 4x -9 = 0 [-20, 20]
I unfortunately have no idea what that means.
- I also have to another similar to that involving mortgage rates. Using the formula
R= (Pr) / (1-(1+r)^-n
And write an interactive program that asks the user about P, n, and yearly interest rate, and then compute R and print it out. It should go something like this:
How much will you borrow?
12000
How many years is that for?
10
What is the yearly interests rate?
0.06
Your payment will be $133.225 a month for 120 months.
- So then I have to write a program that that will print out a periodic monthly schedule for a loan, for as long as the amount of years specified. Should create a six column table with Month, Payment, Interest, Interest Paid, Total Payment and Balance.
- Then write a program that will print a hexidecimal colored American flag. White stars with blue background and white and red colored stripes which are equal signs. You know, *** and ====
- I also have to write a program that will print out tables of squares and cubes in a user specified range and intervals. How can print out squares?
- Also a program that will convert a decimal number into it's binary equivalent.
Should run like this:
Enter a number:
10
Binary: 1010
- And lastly write a program that converts a decimal number into it's hexadecimal equivalent.
Should run like this:
Enter a number:
26
Hexadecimal: 1A
Good God that is a lot.
Last edited by admin : 02-Dec-2008 at 01:30.
Reason: Please insert your example C/C++ codes between [CPP] and [/CPP] tags
|
|