While loop (C++)

a simple program on while loop

Page 1 of 1

4 Replies - 4623 Views - Last Post: 03 June 2008 - 01:30 PM Rate Topic: -----

#1 aparnasp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-June 08

While loop (C++)

Posted 02 June 2008 - 09:44 PM

I want solution of a simple program using while loop. I'm a beginner in C++ language. My problem is as follows.
Write a program to receive 'n' numbers and display all the numbers that are divisible by 3.
Is This A Good Question/Topic? 0
  • +

Replies To: While loop (C++)

#2 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: While loop (C++)

Posted 02 June 2008 - 10:58 PM

Come on show some code.

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Please post like this:

Thank you for helping us helping you.
Was This Post Helpful? 0
  • +
  • -

#3 ajaymatrix  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 1
  • View blog
  • Posts: 410
  • Joined: 15-May 07

Re: While loop (C++)

Posted 02 June 2008 - 11:42 PM

true..
do show us what u have done so far..
Was This Post Helpful? 0
  • +
  • -

#4 anshuldas  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-June 08

Re: While loop (C++)

Posted 03 June 2008 - 03:42 AM

View Postaparnasp, on 2 Jun, 2008 - 09:44 PM, said:

I want solution of a simple program using while loop. I'm a beginner in C++ language. My problem is as follows.
Write a program to receive 'n' numbers and display all the numbers that are divisible by 3.


Hi
May be this code can help you. One thing i have not handled exception because that might make program look more diffcult as you said you are a beginner.

#include<iostream>
#include<vector>
using namespace std;


int main()
{
	int n;
	char ch;
	vector<int>v1;
	vector<int>::iterator itr;
	do{
	cout<<"Enter the number :";
	cin>>n;
    v1.push_back(n);
cout<<"Enter more 'y' for yes and 'n' for no :";
cin>>ch;
	}while(ch=='y');

for(itr=v1.begin();itr!=v1.end();itr++)
{
	if((*itr)%3==0)
		cout<<"The number divible by 3 is : "<<*itr<<endl;
  }
return 0;
}

Was This Post Helpful? 0
  • +
  • -

#5 polymath  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 52
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: While loop (C++)

Posted 03 June 2008 - 01:30 PM

anshuldas should use the code tags, too, like kya says. Another hint, use the % operator, too.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1