just started c++ class.... we use the absolute c++ book

after starting to read this book i decided to buy c++ for dummies and borrowed a book titled object oriented programming with c++ (book is from india written in english)

i still have no idea where to start on these two problems...
can someone dummy them down to basics and concepts... i dont want the code as i would like to learn this instead of just get the coding.

tatum

2. A government research lab has concluded that an artificial sweetener commonly used in
diet soda will cause death in laboratory mice. A friend of yours is desperate to lose
weight but cannot give up soda. Your friend wants to know how much diet soda it is
possible to drink without dying as a result. Write a program to supply the answer. The
input to the program is the amount of artificial sweetener needed to kill a mouse, the
weight of the mouse, and the weight of the dieter. To ensure the safety of your friend,
be sure the program requests the weight at which the dieter will stop dieting, rather
than the dieter’s current weight. Assume that diet soda contains one-tenth of 1% artificial
sweetener. Use a variable declaration with the modifier const to give a name to this
fraction. You may want to express the percentage as the double value 0.001.

8. The Babylonian algorithm to compute the square root of a number n is as follows:
1. Make a guess at the answer (you can pick n/2 as your initial guess).
2. Compute r = n / guess.
3. Set guess = (guess + r) / 2.
4. Go back to step 2 for as many iterations as necessary. The more steps 2 and 3 are
repeated, the closer guess will become to the square root of n.
Write a program that inputs an integer for n, iterates through the Babylonian algorithm
five times, and outputs the answer as a double to two decimal places. Your answer will
be most accurate for small values of n.

having a little problem with the same exercise this is what i have so far....keep in mind this is only my second week
it will close after I enter in the third unit

``````#include <iostream>
using namespace std;
int main( )
{
int sweetener;
int sweetenerfriend;
int sweetenermouse;
int weightmouse;
int weightfriend;
int amountsoda;
double percent;

cout << "Enter the amount of sweetener to kill a mouse";
cout << " Then press return.\n";
cin >> sweetenermouse;
cout << "Now the weight of the mouse.\n";
cout << "Then press return.\n";
cin >> weightmouse;
cout << "Then press return.\n";
cout << "Enter the dieter's weight at the end of the diet.\n";
cin >> weightfriend;

sweetenerfriend = (sweetenermouse / weightmouse) * weightfriend;
amountsoda = 100 * (sweetenerfriend * percent);
cout << amountsoda << "sodas will kill the dieter.\n";

return 0;
}``````
Sky Diploma commented: Should use code-tags and also should have started a new thread with a link to this one... -2

Anthony , Welcome to Daniweb.
Firstly it is necessary that all the OLD THREADS in this forum remain DEAD. Hence it is not considered well to hijack a thread, secondly to hijack the thread whose last post was about 2 years old.

Secondly the use of [code] [/code] tags would be much appreciated in this forum.

As this is your first post, I guess it is excused to answer the post here itself.

Firstly in your code you use a peculiar variable `percent` which is of type double. The main problem here is that the variable has not been initialised with a value.

Therefore, its no wonder that your code would generate improper results. Inorder to solve it, I shall just give you a tip, that you must initialise the variable with a value.
Read through the question to exactly understand what value has to be initialised to it.

Hope this solves your problem .And next time, PLEASE START A NEW THREAD.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.