Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I've done the while loop part where it displays the number, and I am logged into the linux server so I am able to test
I've done the while loop part where it displays the number, and I am logged into the linux server so I am able to test this out, but does anyone know how to code for the instructions to read "hello.out n" in the command line and then execute my code?
This is what I currently have:
#include
using namespace std;
int main( int argc, char *argv[] )
{
if( argc == 2 ) {
cout
}
else (argc != 2);
{
cout
exit(0);
}
{
int argv[1];
cout
cin >> argv[1];
int sum = 0;
int i = 1;
while(i
{
cout
sum = sum + i;
i++;
}
cout
return 0;
}
}
Objective: Write a program to demonstrate while loops and compute the sum. The main purpose of this homework is to review your understanding of loops. Problem: Using C++, write a program using a while loop to count down from a number and calculate the sum of the numbers starting at 1 and counting to n. The iteration number, n, is read directly from command line, e.g., Jexecutable iteration. Requirement Program must be written in the file hw0/hw0.cpp of the linux server program.cs.uh.edu. The file hw0.cpp is already created in the folder hw0 of your account. Program will be tested in the server. Compile your file as "gt+ hw0.cpp -o hello.ou". If you don't have the executable file hello.out, your score will be 0. Run your file with at least three types of input argument a. Should print "Error" if argument number is not exactly two. For example /hello.out b. Should print "Error" if the argument is negative. For example: /hello.out -2 Error c. For a positive number argument, it should print the numbers ranging from 1 to the argument in each line and "Sum is x" as the last line. For example: /hello.out 5 should print: 1 2 3 4 5 Sum is 15Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started