how to write this program in C++
This is a topic on how to write this program in C++ within the Programmers Corner forums, part of the Technology category; I am trying to figure out the logic for these programs but I can't figure out how to write them:
...
1Likes
-
1
Post By Dushyant Chauhan
-
Uber Newbie
how to write this program in C++
I am trying to figure out the logic for these programs but I can't figure out how to write them:
1.A contest requires teams of 5 numbers each. Write a program that asks for the no. of players and then gives the no. of teams and no. of players left.
2.Program to input a given no of days and find the no. of years,weeks and days out of it.
3.Accept a character between a to j and print the next 4 characters
If anyone can help me with these three programs.
Thanks
-
Tech2 Members
Re: how to write this program in C++
Hi,
I wrote these programs in notepad quickly as I was in office so time was short therefore there can be compiler or run time errors so kindly check. But I made them as accurate as possible.
I Couldn't get your 1st point please elaborate.
Answer to your 2nd need number of years weeks and days:
Code:
#include<iostream.h>
#include<conio.h>
void main()
{
int i=0, j, k;
cout<<"Enter the number of days";
cin>>i;
clrscr();
cout<<i<<" days have:\n";
j = i/365; /*for getting no.of years*/
cout<<j<<" Years ";
j = i%365; /* For taking the remainder which will comprise for the no. of days in a week*/
k = j/7; /* for getting the no. of weeks*/
cout<<k<<" weeks ";
j = j%7 /* For taking the remainder which will comprise for the no. of days*/
cout<<j<<" days";
getch(); /* For holding the output screen*/
}
Answer to your 3rd need of printing series:
#include<iostream.h>
#include<conio.h>
void main()
{
char c;
int i=0, j;
cout<<"Enter the Character between a to j after which the characters are to be printed ";
cin>>c;
clrscr();
j=(int) c; /* typecasting as I wrote this program in notepad and was not sure whether auto conversion will take place in the If loop*/
if(j < 65 && j > 106) /* To check whether the given char is in valid range (ASCII Values corresponding to the characters)*/
{
Cout<<"Invalid range! Please enter Valid Character between a to j! ";
Cin>>c;
clrscr();
j=(int) c; /* typecasting as I wrote this program in notepad and was not sure whether auto conversion will take place in the If loop*/
if(j >= 65 && j <= 106) /* Valid Check*/
{
while(i < 4) /*loop for printing the series*/
{
cout<<"The Sequence is : \n";
j = j + i; /*step for incrementing the characters*/
c = (char) j;
cout<<c<<" ";
i++;
}
}
getch(); /*For holding the output window*/
}
Regards,
Dushyant Chauhan
Last edited by coolpcguy; 06-02-2012 at 08:28 AM.
Reason: use [code] for code blocks
-
Tech2 Members
Re: how to write this program in C++

Originally Posted by
lI0
I am trying to figure out the logic for these programs but I can't figure out how to write them:
1.A contest requires teams of 5 numbers each. Write a program that asks for the no. of players and then gives the no. of teams and no. of players left.
I don't like spoon-feeding, so am just listing the logic for the 1st one, since the other tow have obviously been covered in details.
Since each teams can have 5 members, you divide the player by 5 and store only the integer part of the number. This is your total number of teams. Multiply the number obtained by 5 and then subtract it from the total number of players entered, to get the number players that aren't part of any teams. (Hint: there's a guard code to be implemented here to make the prog a bit intelligent, but I'll leave that to you to discover for yourself.)
If you need any help, post back!
-
Tech2 Members
Re: how to write this program in C++
@morpheus:liked your way of teaching.no to spoon feeding.
-
Tech2 Members
Re: how to write this program in C++

Originally Posted by
Morpheus3000
I don't like spoon-feeding, so am just listing the logic for the 1st one, since the other tow have obviously been covered in details.
Since each teams can have 5 members, you divide the player by 5 and store only the integer part of the number. This is your total number of teams. Multiply the number obtained by 5 and then subtract it from the total number of players entered, to get the number players that aren't part of any teams. (Hint: there's a guard code to be implemented here to make the prog a bit intelligent, but I'll leave that to you to discover for yourself.)
Or you can just take modulo 5 to the total players to find out remaining players.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules