Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,919 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,579 people online right now. Registration is fast and FREE... Join Now!




program in C++

 
Reply to this topicStart new topic

program in C++, beginner in C

koukou
17 May, 2008 - 09:07 AM
Post #1

New D.I.C Head
*

Joined: 17 May, 2008
Posts: 2

There is a puzzle i have to make in C."Two glasses of 50 ml and 70ml, can fill until the end from a tap and empty or one into other or in the sink, with final objective exist precisely 40 ml in someone from the two". I have something in my mind but i would like to see your opinion. thanks. smile.gif
User is offlineProfile CardPM
+Quote Post

Whizzy
RE: Program In C++
17 May, 2008 - 07:17 PM
Post #2

Unregistered





QUOTE(koukou @ 17 May, 2008 - 10:07 AM) *

Two glasses of 50 ml and 70ml, can fill until the end from a tap and empty or one into other or in the sink, with final objective exist precisely 40 ml in someone from the two".


No offense. I don't even think that's a sentence. Please try to explain your needs a little better, proof read it, then add your reply. Also, if you have "something" in mind, please share that as well. If you don't have "code" that's OK, at least tell us your plan and someone may be able to help you analyze that.

+Quote Post

koukou
RE: Program In C++
19 May, 2008 - 05:56 AM
Post #3

New D.I.C Head
*

Joined: 17 May, 2008
Posts: 2

ok I'll try to explain it. If i had a 7-litre(A) and a 5-litre(B ) bowl and access to water. how could I measure exactly 4 litres?
The solution is:1) Fill the A, pour it into the B. At this point "A" bowl has 2 litres in it and "B" is full.
2)I empty "B" and pour with 2litres from A. 3)Fill A with 7 litres and pour 3 litres to B until B is full and A contains 4 litres. This is the solution. The code I have in mind is:
CODE
#include <iostream>
using namespace std;

int  massive(int given,int max_bigger_quantity,int max_smaller_quantity){
    int smaller_quantity=0,bigger_quantity=0,k=1;
       while(smaller_quantity<given){
             cout<<"\t~*~*~*~*~*~*~*~*ROUND "<<k<<"~*~*~*~*~*~*~*~*"<<"\n\n\n\n"<<endl;
             cout<<"\tFilling bigger glass with "<<max_bigger_quantity<<" ml"<<endl;
             bigger_quantity=max_bigger_quantity;
             bigger_quantity=bigger_quantity-(max_smaller_quantity-smaller_quantity);
             k++;
             cout<<"\tMoving "<<max_smaller_quantity-smaller_quantity<<" ml from bigger glass to smaller glass"<<endl;
             cout<<"\tMaking smaller glass empty"<<endl;
             smaller_quantity=bigger_quantity;
             cout<<"\tFilling smaller glass with bigger's quantity: "<<bigger_quantity<<" ml"<<endl;
             cout<<"\tMaking bigger glass empty \n\n\n"<<endl;
       }
       if(given>smaller_quantity)return 0;
       else                     return k;
};
int main(void){
    int times=0;
    times=massive(40,70,50);
    if(times==0)cout<<"Problem cannot be solved"<<endl;
}


User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:02AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month