|
Write a C++ program that reads a positive integer n, and prints the first
n even numbers.
For example, one execution would look like this:
Please enter a positive integer: 3
2
4
6
File Name
evennumbers.cpp
Score
There are three tests each worth 2 points
1.#include<iostream>
2.using namespace std;
3.
4.int main()
5. {
6. int n;
7. cout<<"Please enter a positive integer:";
8. cin>>n;
9.
10. cout<<"These are all even numbers in between 1 to "<
|
|
|
|
|
Well, looks like good and not complicated exercise. Did you solve it?
|
|
|
|
|
Hi it's okay when I run it,but the Autograrder says FAILED.What could be the problem? Should I submit the executable file only.If I rename the executable file as .cpp the Autograder results to errors of 2 .cpp files.What should I do please?
|
|
|
|
|
Sorry, I could not understand what you mean...
The code you've posted is not complete, it doesn't compile and it does nothing.
|
|
|
|
|
Hi it's okay when I run it,but the Autograrder says FAILED.What could be the problem? Should I submit the executable file only.If I rename the executable file as .cpp the Autograder results to errors of 2 .cpp files.What should I do please?
|
|
|
|
|
Please, stop reposting the same!
I've already read it (your post from 1-Mar-22 9:33) And answered!
|
|
|
|
|
How do you expect anyone here to answer? We have no idea what the Autograrder is, or what criteria it uses to judge your code. And unless you show the complete code we cannot suggest any changes.
|
|
|
|
|
So what's the problem, exactly?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Is there any doubt? He wants someone to do his work.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
#include<stdio.h>
int getFactorial(int);
int main(void) {
int n;
printf("Enter n: ");
scanf("%d",&n);
printf("Factorial of %d is %d", n, getFactorial(n));
return 0;
}
int getFactorial(int n) {
}
|
|
|
|
|
Christine Belisario wrote: // how to Implement this recursive function Google will find you many explanations of the factorial function. You just need to think about how you could implement it in code.
|
|
|
|
|
When you've got a plank of code like this, and haven't necessarily begun stepping a mast of methods by leafing through your function library, presumeably squirreled away in the hold in a rat-free database, sometimes it's best to just go to a search engine that's got three sheets to the wind (open to the public), type in each word grain separated by commas and hammer the return.
And marking the returns using your favorites folder by hanging the list of code fragments off the hook of the internet browser you're buckling, for future reference, you're well on your way to driving the sea with your bark of ... lively functions ... and saving CP from a dumb trend which is hopefully on it's way south.
|
|
|
|
|
Prize winner for metaphor density.
|
|
|
|
|
first of all, i shall thanks all of you guys.
In my project, i created some STATIC & EDIT controls in a CDialog and set these control's parent to a group box(also a STATIC control).
it works well for create, but it can't be delete dynamically.
For example, i create 5 EDIT control then delete it(there are no sub-controls in group box this time), and i create 2 EDIT control again, oops! there are 5 EDIT control showing in the group box. So, i guess this caused by the group box haven't refreshed in time. and then i sendmessage to group box to force it to refresh. unfortunately it doesn't works.
here is my code:
<pre lang="C++">
void CPLCDlg::DynamicCreateEdit(UINT nNums)
{
const int YSpace = 15;
const int EHeight = 20;
const UINT EDITID = 72000;
if (nNums <= 0)
return;
CButton* pGroup = (CButton*)GetDlgItem(IDC_STATIC_GROUP);
if (NULL != pGroup)
{
if (NULL != m_pDynEdit && m_siNumsOfDynEdit > 0)
{
for (short i = 0; i < m_siNumsOfDynEdit; i++)
{
if (NULL != m_pDynEdit[i].GetSafeHwnd())
{
m_pDynEdit[i].ShowWindow(SW_HIDE);
m_pDynEdit[i].DestroyWindow();
}
delete m_pDynEdit[i];
}
delete[] m_pDynEdit;
m_pDynEdit = NULL;
::SendMessage(pGroup->GetSafeHwnd(), WM_ERASEBKGND, 0, 0);
}
pGroup->Invalidate(FALSE);
pGroup->RedrawWindow();
pGroup->UpdateWindow();
CRect rcPos;
CString str;
rcPos.SetRectEmpty();
m_pDynEdit = new CEdit[nNums]();
for (short i = 0; i < nNums; i++)
{
rcPos.left = 10;
rcPos.top = 20 + (EHeight + YSpace) * i;
rcPos.right = rcPos.left + 30;
rcPos.bottom = rcPos.top + EHeight;
str.Empty();
str.Format(_T("%d"), i + 1);
if (m_pDynEdit[i].CreateEx(WS_EX_STATICEDGE, _T("EDIT"), (LPCTSTR)str, ES_CENTER | WS_VISIBLE | WS_CHILD | WS_TABSTOP, rcPos, pGroup, EDITID + i))
{
//m_pDynEdit[i].SetWindowText(_T("0"));
}
}
m_siNumsOfDynEdit = nNums;
}
}
</pre>
|
|
|
|
|
Just recreate the dialog? Place it over the old and delete the old, if it's noticeable. (25 cent solution)
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
Rather than destroy and recreate just hide and then show again them!
Do destroy/delete only by destroying the dialog itself!
|
|
|
|
|
Looks like you send a WM_ERASEBKGND message to the parent group window (pGroup) and then redraw it. But parent windows will clip the child windows[^]. This is why you still see the windows you deleted.
In other words when you invalidate/redraw pGroup it skips over the rectangles where your m_pDynEdit child windows were being drawn.
You can use the ExcludeClipRect function[^] to remove the clipped rectangles from the clipping region.
Also, you can use the RectVisible function[^] to check for clipping.
I'm on a TV, I apologize in advance for any typos.
|
|
|
|
|
(I'm not sure there's a better place to ask)
I'm trying to use VS2022 in our build pipeline.
I have a pipeline like this :
Quote: pool:
vmImage: 'windows-latest'
variables:
solution: 'MySolution.sln'
steps:
- task: CmdLine@2
displayName: 'Choco install additional packages'
inputs:
script: |
choco install windows-sdk-8.1 visualstudio2017community microsoft-build-tools-2013 visualstudio2022professional - task: VSBuild@1
displayName: 'Build Debug143|x64'
inputs:
vsVersion: '17.0'
solution: '$(solution)'
maximumCpuCount: true
msbuildArchitecture: 'x64'
platform: 'x64'
configuration: 'Debug143'
I get errors that it cannot find the installation.
Quote: 2022-02-17T18:46:30.0197396Z ##[error]MyProject.vcxproj(77,3): Error MSB4019: The imported project "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VC\v170\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk.
When I put a "dir /s" in my pipeline, it looks like VS2022 is not installed in that path.
I'm not sure what I have to do to make it work.
Any Idea ?
Thanks.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
Not sure if it applies to you but this is the magic incantation I use find latest VS installation:
@echo off
if not "%VSCMD_VER%"=="" (
echo MSBuild environment is already set
goto :EOF
)
if "%VSWHERE%"=="" set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set VSInstallDir=%%i
)
"%VSInstallDir%\common7\tools\vsmsbuildcmd.bat"
Mircea
|
|
|
|
|
Thanks I will look at it.
CI/CD = Continuous Impediment/Continuous Despair
|
|
|
|
|
I just noticed the bad formatting. Sorry, it's from CP not me.
I tried editing my post but in the edit box the text shows OK. Not sure what's going on but smells like a bug.
Mircea
|
|
|
|
|
Message Closed
modified 15-May-23 19:07pm.
|
|
|
|
|
\u001B is an "escape" (27).
"Before entering on an understanding, I have meditated for a long time, and have foreseen what might happen. It is not genius which reveals to me suddenly, secretly, what I have to say or to do in a circumstance unexpected by other people; it is reflection, it is meditation." - Napoleon I
|
|
|
|
|
|
They are ANSI escape codes for colors, etc. See, for example, ANSI Escape Codes · GitHub[^]
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|