Could u check if i correctly answered these programs, just not sure if i answered question properly.


Write a C++ program that reads from keyboard 3 integers, with proper input prompt, and then displays the maximum sum of any pair of numbers from these three. If the 3 numbers are 5, 6 and 7 for instance, then the maximum sum comes from 6+7=13. Draw the flowchart of this C++ program, and also desk check the program for the three input integers 12, 3 and 7, or a different set of 3 numbers which will make the desk checking less trivial within your program design.

#include<iostream>

using namespace std;

int main()

{
int num1,num2,num3,high1,high2,maxSum;
cout << "Please enter 3 numbers seperated by space: ";
cin >> num1>>num2>>num3;
{
if (num1 < num2)
{
high1 = num2;
high2 = num3;
maxSum = num2 + num3;
}
else if (num2 < num1)
{
high1 = num1;
high2 = num3;
maxSum = num1 + num3;
}
else if (num3 < num1)
{
high1 = num1;
high2 = num2;
maxSum = num1 + num2
}
cout << "\n";
}
cout << "The Maximum Sum of " <<high1;
cout << " and " <<high2;
cout << " is " << maxSum << endl;
system("pause");
return 0;
}


2. (4.5 marks) Suppose a deposit of certain amount is made to the same bank account each year on 1 July, and the annual interest rate for this account is always 0.08 (8%). Write a C++ program that reads in these yearly deposits, calculates and displays the total accumulated amount of the account on 1 July of the current year. A negative deposit amount or an invalid deposit input will terminate the program input. Hence for a list of deposits such as
1000
3500.50
2000
-1
(2 years ago deposited on 1 July)
(1 year ago deposited on 1 July)
(deposited on this 1 July)
(or control-Z, calculate the accumulation on this 1 July)
the program should produce the accumulated total 6946.94 = 1000*1.082 + 3500.50*1.08 + 2000 or through 6946.94 = (1000 *1.08 + 3500.50) *1.08 + 2000.

#include <iostream>
using namespace std;
int main ()
{
double dep1,dep2,dep3,dep4,Salary;
//Declaring Variables
cout<<"What was the deposited amount 2 years ago on July 1st: "<<endl;
cin>>dep1;
cout<<"\nWhat was the deposited amount 1 year ago on July 1st: "<<endl;;
cin>>dep2;
cout<<"What was the deposited amount this July 1st: "<<endl;
cin>>dep3;
cout<<"how much has been deposited next year: "<<endl;
cin>>dep4;
Salary=(dep1 * 0.08 + dep2) * 0.08 + dep3;
cout<<"The Annual Salary is: "<<Salary<<endl;
system("pause");
return 0;

}

3.(1.5 marks) Write a C++ function isPrimeNumber prototyped by
bool isPrimeNumber (long num);
that return true if num is a prime number and returns false if otherwise. Then write a driver program that finds and displays all the prime numbers between 1 and 1000, and also displays the total number of the prime numbers found this way. We note that a positive integer num is a prime number if and only if none of the integers from 2 to (num-1) can divide num completely.


#include <iostream>
using namespace std;

bool isPrimeNumber(long num);

int main()
{
int numPrimesFound = 0;

for (long i = 2; i < 1000; i++)
{
if (isPrimeNumber(i))
{
numPrimesFound++;
std::cout << "Prime #" << numPrimesFound << ": " << i << std::endl;
}
}
system("pause");
return 0;
}

bool isPrimeNumber(long num)
{
if (num < 2)
return false;
else if (num == 2)
return true;
else
{
for (long i = 2; i < num; i++)
{
if (num % i == 0)
return false;
}
}
return true;
}


My apologies that all this is so long, but i was just wondering if you guys could check over my codes and tell me if there wrong and give me some tips if i need to fix it.
[code] "Please use code tags" [/code]
Keep console open http://www.cplusplus.com/forum/articles/7312/
Why system is evil http://www.cplusplus.com/forum/articles/11153/

1. Consider this input: 500 501 2
2. Who told you that were 2 years of input?
3. Looks fine, but it is inefficient.
Oh dam. Any hints on how i could fix problems 1 and 2?
Topic archived. No new replies allowed.