Hello all,

The program I am working on is calculation of areas (of shapes). For example, for triangle area calcuation I have:

else if (character == 't')
    {
        double b,h;
        cout << "Enter base: ";
        cin >> b;
        cout << "Enter height: ";
        cin >> h;
        area= h * b/2;
        cout << "The area of the triangle is: " << area << endl;

I would like to ask the user to specify the number of times he would like to calculate the area, then proceed to asking the parameters. In other words, how many triangles he would like to find the area to. So far I thought of putting each calculation (square, rectangle, etc..) into a function, and asking the user the number of times, then multiplying that number by the function (all theory of course since I have no clue how), but I'm sure there's a better way. If someone could help me with the most efficient way, I would greatly appreciate it.

Thank you

If someone could help me with the most efficient way, I would greatly appreciate it.

Your code is I/O bound, "efficient" shouldn't enter your vocabulary unless user testing shows perceived performance to be unacceptable. Though since you asked, I would prefer accepting a series of base/height pairs on the same line. That way you don't keep bugging the user with prompts:

string line;

if (getline(cin, line)) {
    stringstream sep(line);
    double base, height;

    while (sep >> base >> height)
        cout << "The area of the triangle is: " <<  height * base / 2 << '\n';
}

Your code is I/O bound, "efficient" shouldn't enter your vocabulary unless user testing shows perceived performance to be unacceptable.

Thank you.

However, your reply is the most inefficient way of helping. A suggested solution without an explanation or any comments isn't very useful in my case. And I agree with it needing to be on the same line.

However, your reply is the most inefficient way of helping.

If by "inefficient" you mean that your problem is solved more slowly due to being forced to actually learn something, then I agree. But my goals are different from yours; I'm interested in the bigger picture of teaching programming while you're just interested in solving the immediate problem.

A suggested solution without an explanation or any comments isn't very useful in my case.

Unless your case is acute mental retardation, a C++ reference site and about five minutes of thought are all that's needed to understand the code without any explanation or comments. And the reference site is optional.

But my goals are different from yours; I'm interested in the bigger picture of teaching programming while you're just interested in solving the immediate problem.

Irrelevant and off topic.

Regardless of what you believe my reasons for posting are, if you aren't providing constructive criticism nor helping, don't post.

Unless your case is acute mental retardation, a C++ reference site and about five minutes of thought

Mental retardation or not, your place is not to make assumptions, but rather to assist in solving the problem (if you decide to post). In case you hadn't noticed, I marked this thread as "Solved" before your second and most unhelpful post.

But again, I thank you for taking the time to reply. Now allow me to help you, Julienne.

http://www.daniweb.com/forums/faq.php?faq=daniweb_policies

if you aren't providing constructive criticism nor helping, don't post.

I did help you. You simply didn't accept it. I won't make the same mistake again.

Now allow me to help you, Julienne.

http://www.daniweb.com/forums/faq.ph...niweb_policies

If any of those rules are unclear to you, I'll be happy to explain them. Interpretation and enforcement of the rules are part of my job as community admin, after all. :)

This question has already been answered. Start a new discussion instead.