Question

In: Computer Science

Using C++ : What am I doing wrong!?!? Problem Instructions: Implement a program that repeatedly outputs...

Using C++ : What am I doing wrong!?!?

Problem Instructions: Implement a program that repeatedly outputs an I of a size entered by the user. Prompt the user for a size. If -1 is entered, quit the program. If an even number or a number smaller than 3 is entered, prompt the user again. Then output a shape of # characters that represent an I. Repeat the program until -1 is entered.

What I have so far:

#include <iostream>

#include <iomanip>

using namespace std;

int main()

{

int num;

cout << endl;

cout << " Please enter an ODD number greater than 2: " << endl;

cin >> num;

if (num!= -1)

{

while (num >= 3 && num % 2 == 1)

{

do //Runs if num is invalid

{

if (num %2 == 0)

{

//header

for (int i = 1; i <= num; i++)

{

cout << "#";

}

//middle

for (int i = 1; i <= num; i++)

{

cout << endl;

for (int i = 1; i <= num / 2; i++)

{

cout << " ";

}

cout << "#";

}

cout << endl;

//footer

for (int i = 1; i <= num; i++)

{

cout << "#";

}

}

} while (num >= 3 && num % 2 == 1);

}

}

return 0;

}

Solutions

Expert Solution

If you need any corrections/clarifications kindly comment.

Please give a Thumps Up if you like the answer.

Program

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int num;
cout <<"Please enter an ODD number greater than 2: ";
cin >> num;
cout << endl;
while(num!= -1)
{
if ((num %2!= 0)&&(num>2))
{
//header
for (int i = 1; i <= num; i++)
{
cout << "#";
}
//middle
for (int i = 1; i <= num; i++)
{
cout << endl;
for (int i = 1; i <= num / 2; i++)
{
cout << " ";
}
cout << "#";
}
cout << endl;
//footer
for (int i = 1; i <= num; i++)
{
cout << "#";
}
}
cout <<"\nPlease enter an ODD number greater than 2: " ;
cin >> num;
cout << endl;
}
cout <<"Quitting!!!"<<endl;
return 0;
}

Output


Related Solutions

What am i doing wrong. I want for the program to run through then when it...
What am i doing wrong. I want for the program to run through then when it gets to "do you want to play again?enter yes or no" if they choose yes I want it to run again if they choose no then end. def play(): print("Welcome to the Game of Life!") print("A. Banker") print("B. Carpenter") print("C. Farmer") user_input = input("What is your occupation? ").upper() if user_input == "A": money = 100 elif user_input == "B": money = 70 elif user_input...
What am I doing wrong in this titration problem? Calculate the ph at the equivalence point...
What am I doing wrong in this titration problem? Calculate the ph at the equivalence point for the following titration 0.20M HCl versus 0.20M methylamine (CH3NH2). The Ka of methylammonium is 2.3x10^-11. First I have to divide .20M methylamine by 2 (Why?) to get .10M Then, I set up the equilibrium: (2.3 x 10^-11) = x^2 / .10M Since the ka is SO small, I just multiplied .10 with (2.3 x 10^-11) to get 2.3x10^-12, which is wrong. Why is...
I just need 3 and 5. I am not sure what I am doing wrong. I...
I just need 3 and 5. I am not sure what I am doing wrong. I get different numbers every time. Superior Markets, Inc., operates three stores in a large metropolitan area. A segmented absorption costing income statement for the company for the last quarter is given below: Superior Markets, Inc. Income Statement For the Quarter Ended September 30 Total North Store South Store East Store Sales $ 4,800,000 $ 960,000 $ 1,920,000 $ 1,920,000 Cost of goods sold 2,640,000...
What am I doing wrong in my bootstrap code for R? x<-c(30, 37, 36, 43, 42,...
What am I doing wrong in my bootstrap code for R? x<-c(30, 37, 36, 43, 42, 43, 43, 46, 41, 42) n = 10 x=pnorm(n,mean=40.3,sd=4.6) mu_0=40.3 s.mean=mean(x) s.sd=sd(x);s.sd [1] NA t.sample=(s.mean-mu_0)/(s.sd/sqrt(n)) B=10000 t=c() count.less=0 count.more=0 for(j in 1:B) + { b.smpl = x[sample(1:n, size = n,replace=TRUE)] + ybar.bs = mean(b.smpl) + sd.bs = sd(b.smpl) + t[j] = (ybar.bs - s.mean)/(sd.bs/sqrt(n)) + if(t[j]>=t.sample){ count.more=count.more+1} + if(t[j]<=t.sample){ count.less=count.less+1} + } Error in if (t[j] >= t.sample) { : missing value where TRUE/FALSE...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class...
what am I doing wrong here? thank you! #include <iostream> #include <string> using namespace std; class DivSales { private:    int quarterSales[4];    static double totalSales; public:    void add(int, int, int, int);    int sales(int);    static double getValue()    {        return totalSales;    };    void DivSales::add(int s1, int s2, int s3, int s4)    {        quarterSales[0] = s1;        quarterSales[1] = s2;        quarterSales[2] = s3;        quarterSales[3] = s4;...
Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
I am currently working on this problem. It says it is wrong, and I was wondering...
I am currently working on this problem. It says it is wrong, and I was wondering if someone could correct my code to where its ouput is as followed. Expected Output: 6↵ 5↵ 4↵ 3↵ 2↵ 1 Actual Output: 9↵ 8↵ 7↵ 6↵ 5↵ 4↵ 3↵ 2↵ 1↵ 0↵ 9.10: Reverse Array Write a function that accepts an int array and the array’s size as arguments. The function should create a copy of the array, except that the element values...
Can you write this program, but in python, I just wanna see what am I doing...
Can you write this program, but in python, I just wanna see what am I doing wrong. thank you Instructions: The Gas-N-Clean Service Station sells gasoline and has a car wash. Fees for the car wash are $1.25 with a gasoline purchase of $10.00 or more and $3.00 otherwise. Three kinds of gasoline are available: regular at $2.89, plus at $3.09, and super at $3.39 per gallon. User Request: Write a program that prints a statement for a customer. Analysis:...
I am doing an experiment recording the speed of sound. I am using an open-ended cardboard...
I am doing an experiment recording the speed of sound. I am using an open-ended cardboard tube that is 76.2cm (30") and the temperature in my room is 75 degrees or 23.89 celsius. What is my speed of sound (using the speed of sound expression with explanation please)? Given the length of my tube, what are my first five wavelengths that my tube should resonate (using the standing sound wave formula)? What are my five wavenumbers (k) of the above...
Can't figure out what I am doing wrong. Please let me know. Sample output: Please enter...
Can't figure out what I am doing wrong. Please let me know. Sample output: Please enter the name of the weather data file: temperatures.txt Tell me about your crew’s preferred temperature for sailing: What is the coldest temperature they can sail in? 60 What is the hottest temperature they can sail in? 80 Month 1: 93.3 percent of days in range. Month 2: 20.0 percent of days in range. Month 3: 58.1 percent of days in range. Month 4: 100.0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT