Noob help needed!

Pages: 12
Hi guys, I've started c++ at school and am having very difficulty finding soloutions to answers and writing code. I'm even attending after class lessons but still not getting it. I understand the thoery but the insertion of code messes my mind.I know the only way to improve is to do it own my own but can some 1 help me get this question started. I know this doesnt mean anything but this subject is mandatory :(

Question: 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.

Question: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 (2 years ago deposited on 1 July)
3500.50 (1 year ago deposited on 1 July)
2000 (deposited on this 1 July)
-1 (or control-Z, calculate the accumulation on this 1 July)


The program should produce the accumulated total 6946.94 = 1000*1.08(2) + 3500.50*1.08 + 2000 or through 6946.94 = (1000 *1.08 + 3500.50) *1.08 + 2000

Cheers guys!
cheers kbw, reading up now.
!bump
any one else?
What have you tried?
just write some nice loops to try every combination?
I wouldn't use a loop if there are only 3C2 = 3 combinations to try.
Start with what you know, and then post it.
had like 10 minuets to slack off so heres number 1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main()
{
	cout << "please enter 3 numbers: " << endl;

	int numbers[3];

	for (int i = 0; i <= 2; i++)
	{
		string entered;
		cin >> entered;
		stringstream(entered) >> numbers[i];
	}

	int largest = 0;

	for (int i = 0; i < 3; i++)
	{
		for (int y = 3; y > 0; y--)
		{
			if (numbers[i] + numbers[y] > largest && numbers[i] != numbers[y])
			{
				largest = 0;
				largest = numbers[i] + numbers[y];
			}
		}
	}

	cout << largest << endl;
	system("pause");
	return 0;
}
@ascii: Don't just post solutions, it helps more if the TC figures it out themselves.
yeah, im not going to use that just see what its like.
what is the reason for having i and y in brackets?
cheers
@firedraco

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.

I used my book and help u gave me and for that question got this:

#include <iostream>

using namespace std;

int main()
{

int num1, num2, num3, first, second;

cout << "Please enter your first number: ";
cin >> num1;
cout << "Please enter your second number: ";
cin >> num2;
cout << "Please enter your last number: ";
cin >> num3;
cout << num1 << " " << num2 << " ";

system ("pause");
return 0;
}

it works however it doesnt tell me the maximum sum of the 2 largest numbers.
any ideas?
That's because you aren't doing anything after getting the 3 integers. If you had three numbers, how would you find the largest sum of two of them?
if statement?

if (num1 > num2 > num3, sum = num1+num2);?
You are on the right track, but your syntax is incorrect.

You can't have 3 comparisons all in a row like that, you must seperate them:
num1 > num2 && num2 > num 3

Also, your , sum =... stuff shouldn't be in the if statement.
See: http://cplusplus.com/doc/tutorial/control/
let me try to break down my program and excuse me if i sound stupid because i started learning C++ today


lines 1-8:
include the three header files i need, (iostream, strings and stringstream) and start the main function

lines 9 - 18:
i make an array to store the three numbers the user enters and have them enter the numbers, then convert them into and int type and add them to the array.

lines 19 - 32:
declare a variable called largest, which will store the answer later on. i create two for loops, one within the other, and the essentially try every possible combination like this:


num1 + num2;
num1 + num3;

num2 + num1;
num2 + num3;

num3 + num1;
num3 + num2;


if the combination is larger than the previous largest value that the program found then it stores it in the variable largest. the second condition of the if statement makes sure that it doesnt just add the greatest number to itself because then it wouldnt be adding two numbers.

lines 33-37:
print out the answer and terminate the program


hopefully this makes a little bit more sense. once again i started learning C++ today so please dont judge me xD also read the section firedrako linked and if you can go through the entire tutorial from start to finish, only moving on to the next chapter if youre sure you understand what each section says.
thanks for your help guys:(
im trying to read but it just doesn't sink through. probably shouldn't have chosen it at uni lol.
i understand the theory but when it comes to inputing it in the program i suck.
i think im just gonna hand it in a cop it on the chin. just to hard.
cheers
just keep going at it man, usually you learn in breakthroughs. youll be confused by something, then have a breakthrough that lets you get to the next thing! youll have an "oh it makes sense!" moment soon enough
thanks man. im trying with the one i programmed. a lot easier for me to read than yours. can u pm me ur email or allow pm's to be received in your user. that would be awsome. cheers
yeah you can pm now but i dont know of how much help ill be im not very good at C++
Pages: 12