Homework Help

Please,give one or two programmes using do...while loop in c++?          

user profile pic

gazala | Student, Undergraduate | eNotes Newbie

Posted October 9, 2010 at 11:24 PM via web

dislike 0 like

Please,give one or two programmes using do...while loop in c++?

 

 

 

 

 

2 Answers | Add Yours

user profile pic

crmhaske | College Teacher | (Level 3) Associate Educator

Posted October 10, 2010 at 12:11 AM (Answer #1)

dislike 0 like

A do while loop in C++ is a block of code that executes so long as the condition of the do while are being met.  Once they cease to be met, the program exits the loop.  For instance (in plain English):

do count while count is less than twenty

In C++ this would look like:

int count=0;

do {
count ++;
} while (count<20);

user profile pic

satavisha | Student, Grade 9 | eNoter

Posted February 10, 2011 at 8:01 PM (Answer #2)

dislike 0 like

Here is a program on interest calculation using do while loop

#include<iostream.h>

#include<conio.h>

float cal (float amt, int year, float rate=15);

void prn (char c='*');

void main ()

{

clrscr();

float amount, interest;

int year;

cout<<"Enter the amount on which interest has to be calculated: -";

cin>>amount;

cout<<"Enter the number of years: -";

cin>>year;

interest=cal (amount, year);

prn ();

cout<<"The interest on-"<<amount<<"-for the period of-"<<year<<" years would be"<<interest<<endl;

prn ('-');

getch ();

}

float cal (float amt, int year, float rate)

{

int i;

float sum=amt;

i=1;

do

{

sum=sum * (1+ (rate/100));

i++;

}while(i<=year);

return sum-amt;

}

void prn (char c)

{

for (int i=0; i<40; i++)

{

cout<<c;

}

cout<<endl;

}

 

 

Join to answer this question

Join a community of thousands of dedicated teachers and students.

Join eNotes