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
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?
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