Either way, the principle remains the same.
1. accept user inputs into an array of appropriate type
2. use a loop to achieve desired output (which in this case is to display the array reverse order)
Either way, the principle remains the same.
1. accept user inputs into an array of appropriate type
2. use a loop to achieve desired output (which in this case is to display the array reverse order)
I'm not sure if this is related to your problem, but I'm pretty sure you aren't allowed to just declare arrays of a given size on demand:
cout <<endl<<"Please enter the size of the array you want to sort: ";
cin >> mysize;
//no bueno
int mylist[mysize];
I think you have to either be up front and declare an array of an arbitrary size, or create a dynamic array of whatever size you want.. but trying to declare an array of variable size is not allowed.
Try this instead:
cout <<endl<<"Please enter the size of the array you want to sort: ";
cin >> mysize;
//simple dynamic array
int *mylist = new int[mysize];
U mean using for loops?
To be quite honest, I believe it is possible to use any type of loop structure for any given situation. But yes, 'for' loops seem to be the defacto standard when it comes to array operations... but any loop you decide to use will work just fine.
char number[50];
cout << "Enter a number: ";
cin >> number;
//using do/while
int i = strlen(number);
do{
cout << number[i];
i--;
}while(i >= 0);
//using while
int i = strlen(number);
while(i >= 0)
{
cout << number[i];
i--;
}
//using for
for(int i = strlen(number); i >= 0; i--)
{
cout << number[i];
}
//using a function from <algorithm>
int end = strlen(numbers);
reverse(&numbers[0], &numbers[end]);
cout << numbers;
These are very basic array operations. The goal of this assignment was to teach you that you can use any loop structure to perform any array operation you desire.
For most assignments of this nature, most go with storing user input into a cstring.. then use a loop to display the contents of the string in reverse order.
Simple. Straight-forward.
You are attempting to perform a switch test on a char[50] array. In c++, the switch structure is designed to perform tests on the current state of a single integral expression (the most commonly used are 'int' and 'char').
Additionally, even if you were testing the correct data type, the syntax of the rest of your switch structure does not make sense and is syntactially incorrect. Here is an example:
//Cannot perform a switch on cstrings (why do you have string literals in char notation?)
case 1: 'January'
//Here we have boolean logic.. but where is the if( ) ??!?
d>=1&&d<=31;
//Even if your condition tested true.. what do we do now??!? (You have NOTHING)
break;
Here is one example of a correct switch:
switch(m[0])
{
case 'J': //Do something useful
break;
case 'F': //Dazzle us with your coding skills
break;
case 'M': //More c++ goodness goes here
break;
...
....
etc. etc.
Although the aforementioned scheme is not perfect (several months start with the same first letter and provisions should be made to account for such cases), at least it is a demonstration of a good working switch.
Another option would be to use if() else logic to perform tests on your cstrings:
if(strcmp(m, "January"))
{
if( !(d >= 1 && d <= 31))
{
prompt_error_message();
}
}
....
......
etc etc.
I think someone needs a hug.
I'm confused with pointers.
pointer-type variables hold memory addresses.. just like int's hold integers, char's hold ascii values etc.
I'm not sure how to get the vowels to show up in Case A
Although I do not agree with your current scheme of prompting for user input after a menu selection is made (I think it should be done before being that all your menu options are based on the same user input), here is one way to "get the vowels to show up"...
void getStringFromUser()
{
char line[100];
cout << "Enter a string: ";
cin.getline(line, 100, '\n');
cin.ignore();
for(int i=0, i<strlen(line), i++)
{
switch(toupper(line[i]))
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': vowel_counter++;
}
}
}
Also, I would need help by how to get the program to run again after case A instead of ending the program after each case.
Although this may seem rather complex, I'll break it down for you as best as I can:
char ans = '\0';
//Add this at line #29
do{
//Add this at line #63
cout << "Do you wish to make another menu selection? (Y/N) ";
cin >> ans;
}while(toupper(ans) == 'Y');
Should it be in if/else statement instead of switch?
No. Menu options should be handled using switch structure.
Or use while loop with switch statement?
Yes, and this is what I've done for you.
The code I have given you is untested and my contain small easy to fix errors. …
Line #23: you have an unecessary } curly brace
main() does not return any value, although you have it prototyped to return an 'int'.
Line #25: should be // commented out
You should have a } curly brace after line #24
The parameter list in line #26 does not match its prototype in line #12.
I know I can use a search to find where the first instance of something happens, but how do I actually take whats before it?
I see that you seem to be interested in using <string> class member functions for your parsing needs. May I suggest the following which uses find() and substr():
string expression = "+3 3/4";
string terms[10];
int prev = -1, curr = -1;
int i=0;
while(curr != string::npos)
{
prev = curr;
curr = expression.find(' ');
if(curr != string::npos)
{
//Feel free to make any adjustments you need to extract the desired substring
terms[i] = expression.substr(++prev, (curr-prev));
}
i++;
}
This may or may not be specifically what ye' are asking for, but should be able to point ye' in the right direction. In the above example, I obtained the first occurance of a white space, then stepped forward one element and extracted a "term" substring which I stored into the terms[] array.. feel free to affect the substr() arguments to return a substring of your chosing.
The above code is untested and may contain easy to fix errors. It is intended to be a suggestion only. Suggestions for improvement are always welcome.
Here is a possible pseudo-code for what ye' wish to accomplish:
1. Prompt the user for 5 numbers:
do{
cout << "Enter a number: ";
cin >> user_picks[i];
i++;
}while(i<5);
2. Ensure that user did not make a duplicate pick:
do{
cout << "Enter a number: ";
cin >> user_picks[i];
//You will design the is_duplicate() function
if(is_duplicate(user_picks[i]))
{
cout << "\aError! Number already used!";
i--;
}
i++;
}while(i<5);
3. Generate 5 random non-duplicated numbers:
//Seed random number generator
srand(time(NULL));
//Populate lotto[5] array with 5 unique integers
for(int i=0; i<5; i++)
{
lotto[i] = rand()%55+1;
//You will design the is_duplicate() test
if(is_duplicate(lotto[i]))
{
i--;
}
}
4. Compare the user_picks[5] array with the lotto[5] array:
for(int i=0; i<5; i++)
{
for(int j=0; j<5; j++)
{
if(user_picks[i] == lotto[j])
{
match++;
}
}
}
5. Display useful information to the user:
cout << "Your numbers: ";
for(int i=0; i<5; i++)
{
cout << user_picks[i] << ' ';
}
cout << "Official lottery drawing: ";
for(int i=0; i<5; i++)
{
cout << lotto[i] << ' ';
}
cout << "You have successfully matched " << matches << " numbers!";
I have just spoon fed you a lot of useful information that no one else would give you without any effort or attempt at programming on your part so I suggest you take this pseudo-code and run with it.
But then how can i convert the grades to grades (letter) i.e. (a, b, c, c, or f)? I am still confused.
I'm not sure what you are trying to do, but maybe this will help:
//Function Prototype
char get_grade(int&);
//Display Grades
for(int i=0; i<10; i++)
{
cout << students[i] << " scored " << grades[i] << "% which is a " << get_grade(grades[i]) << endl;
}
//Function Definition
char get_grade(int& score)
{
if(score < 60)
return 'F';
else if(score >= 60 || score <= 69)
return 'D';
else if(score >= 70 || score <= 79)
return 'C';
else if(score >= 80 || score <= 89)
return 'B';
else
return 'A';
}
I dont think its to do with this part...
Your mixing of >> extraction and use of getline() combined with your complaint of segmentation fault warrants the viewing of your .txt file data format.
Here is your attempt to read in the .txt file:
while (!inFile.eof())
{
inFile >> w;
getline(inFile, m, '\n');
l.insert(w, m);
cout << "Enter your choice: " << endl;
cin >> choice;
In the above code, you read in the first word of the .txt file using the >> extraction operator, then read in the remainder of the line using getline(). With only the first word and first line extracted from the .txt file, you immediately begin prompting the user for menu choices. Therefore, using the above code, you would have prompt the user once for every line in your .txt file in order to read in the entire file content.
My suggestion would be to read in the entire file first, and then prompt to user for menu choice after the entire file has been loaded:
string w[15], m[15];
int i=0;
//Load the file using a safer method than testing for eof()
while(infile >> w[i])
{
getline(inFile, m[i], '\n');
i++;
}
//Now that the file is loaded, begin prompting for user action
char ans = '\0';
do{
cout << "Enter your choice: ";
cin >> choice;
switch(choice)
{
case 1: l.traverse();
break;
case 2: l.lookUp(w);
case 3:
break;
default: cout << "Not a menu choice, try again.";
}
cout << "Do …
As with any file I/O, I will need to see how your txt file data is formated.. white spaces and new lines are important factors to consider when trying to troubleshoot file I/O.
3*-4. Any ideas around this?
In the evaluation of polynomial expressions, it is safe to treat all " - " minus signs as preceding negative numbers (it is safe to assume there is no subtraction). The only special case one must consider is the case of the double negative, wich can be easily tested for.
Example:
-3x^2-4x = -5
Can trasnlate to:
Negative Three x squared plus negative four x = negative 5
Notice that there is no "subraction" involved with the evaluation of polynomials. With the exception of the double negative, you can safely assume all minus signs are only to identify negative values.
If your program supports only the basic math operations (addition, subraction, multiplication and division) between your polynomial terms, then all you really have to identify is * multiplication and / division... everything else is addition.
Try this funciton from <algorithm>
#include<algorithm>
int array[10000];
fill(&array[0], &array[10000], 0);
The problem is that the array size is unknown.
int size = sizeof(array) / sizeof(array[0]);
Is there any way to sort such an array without any lengthy procedures?
#include<algorithm>
sort(array[0], array[size]);
Re: The last suggestion you made of making a Student object with 100 objects. This cannot be done as the user has to tell me how many students are on the roster. I have already have this created dynamically so that can be taken care of. Your suggestion of the default constructor did work for me though. This is the type of simple stuff I overlook.
I am aware of this.. I was just trying to demonstrate how you could create a bunch of objects of a certain class and know that all those objects have been initialized via the class default contructor.
Although I am by no means a network administrator, this assignment doesn't really seem that overly complex...
Here is how one can determine the IP class:
Class A: Class A addresses are specified to networks with large number of total hosts. Class A allows for 126 networks by using the first octet for the network ID. The first bit in this octet, is always set and fixed to zero. And next seven bits in the octet is all set to one, which then complete network ID. The 24 bits in the remaining octets represent the hosts ID, allowing 126 networks and approximately 17 million hosts per network. Class A network number values begin at 1 and end at 127.
Class B: Class B addresses are specified to medium to large sized of networks. Class B allows for 16,384 networks by using the first two octets for the network ID. The two bits in the first octet are always set and fixed to 1 0. The remaining 6 bits, together with the next octet, complete network ID. The 16 bits in the third and fourth octet represent host ID, allowing for approximately 65,000 hosts per network. Class B network number values begin at 128 and end at 191.
Class C: Class C addresses are used in small local area networks (LANs). Class C allows for approximately 2 million networks by using the first three octets for the network ID. In class C address three bits are always set …
I would then suggest maybe trying a char hex[20][20] array. (This will be a char[row][column] 20x20 square array).
Initialize all the array elements to a white space:
for(int i=0; i<20; i++)
for(int j=0; j<20; j++)
{
hex[i][j] = ' ';
}
Now I would suggest using a piece of graph paper and figure out what elements ye' would like to populate to draw a hexagon.
hex[3][10] = '*';
hex[4][11] = '*';
hex[5][12] = '*';
hex[6][11] = '*';
...
...
etc etc.
Now you can draw your entire hexagon with one nested for loop:
for(int i=0; i<20; i++)
{
for(int j=0; j<20; j++)
{
cout << hex[i][j];
}
cout << endl;
}
This should give ye' at least an idea. I'll draw half of the hexagon, ye' can do the rest. This is untested, but feel free to tweak it as necessary to draw that perfect hexagon:
#include<iostream>
#include<iomanip>
void draw_hex()
{
//Draw Top
cout << setw(10);
for(int i=0; i<5; i++)
{
cout << '*';
}
cout << endl;
//Draw Top Sides
int left_offset = 10, right_offset = 5;
for(int i=0; i<5; i++)
{
cout << setw(--left_offset) << '*' << setw(right_offset+=2) << '*' << endl;
}
//Draw Bottom Sides
...
...
...
//Draw Bottom
...
...
...
}
You declare main() to return an 'int' type... but nowhere do you have a 'return' statement in your main() function.
int main()
{
...
...
yadda yadda
....
...
etc etc.
....
...
...
return 0;
}
char ans = '\0';
int i=0;
do{
cout << "\nEnter a number: ";
cin >> arr[i];
cout << "\nWould ye' like to enter another number? (Y/N) ";
cin >> ans;
i++;
}while((ans == 'Y' || ans == 'y') && i < SIZE);
Try using getline(cin, user_input);
edit: went to go take a wiz, when I came back ya'll had the answers already.
What you are suggesting is very possible, just change the desired function to accept a char parameter. Then at some point, you can use if/else logic based on that char argument to determine what type of problem ye' wish to produce.
- BOTH HEADER FILES AND RELATED FUNCTIONS: I changed over my char arrays to strings (the project calls for maximums of characters). How do I easily change these over?
This doesn't seem like it would be that big of a deal. Change the header from <cstring> to <string>. Anytime you want to compare string objects use == instead of strcmp(), anytime you want to assign stuff to your string, use the assignment operator = instead of strcpy(), anytime you want to add to a string, use += instead of strcat(), etc, etc.
- ROSTERAPP.CPP: in displayStudent I have a comment for the loop if the entered number is found, but sometimes I get a FC. What am I doing wrong?
The success of this test depends on getID() to return non-zero "TRUE" if studentID exists, or return 0 "FALSE" if studentID has not been populated:
if (stu[id].getID() == false) //WORKING, but not the way it should... causes an FC error
As of right now, whenever a 'Student' object is created, none of the private variables are ever initialized.. so even if you create a new 'student' object, there is no guarantee that studentID will be zero (false), even though it has not been assigned anything. To make sure studentID is zero whenever new 'student' objects are created, we will make a simple default constructor. This is a function that will automatically get called every time a new 'student' object is created. We can use this feature to initialize …
and then could NOT figure out how to change the parameters of my doOneSet function to do addition, subtraction and multiplication
There are many ways to go about this. Since you seem interested in changing the parameter list of your doOneSet() function... maybe we could do something like this (ok, I changed the parameter list of your doOneProblem() function instead.. it was easier for me)
void doOneSet()
{
//simple loop will call the doOneProblem() function 5 times
//instead of having to write out each individual function call
for(int i=0; i<5; i++)
{
//Here we will supply a random number: 0,1 or 2
//we'll make 0 = add, 1 = subtract, and 2 = multiply
doOneProblem(rand%3);
}
}
Now when you get down to calcCorrectAnswer(), you could have something like this:
void calcCorrectAnswer(int &result, int &userNum1, int& operation)
{
int num1, num2;
switch(operation)
{
//addition
case 0: cout << num1 << " + " << num2 << " = ";
cin >> userNum1;
result = num1 + num2;
break;
//subraction
case 1: cout << num1 << " - " << num2 << " = ";
cin >> userNum1;
result = num1 - num2;
break;
//multiplication
case 2: cout << num1 << " * " << num2 << " = ";
cin >> userNum1;
result = num1 * num2;
break;
default: cout << "Error..!";
}
checkAnswer(result, userNum1);
}
Even if this isn't exactly what you want, feel free to modify it as you like.. it's mainly here just to give …
You initialize all your string containers to 'white space' and your while() loop condition tests for 'white space' which will always test true (because at no time are they ever changed)
Here is the pseudo code for what ye' wish to accomplish:
1. Accept user input in the proper format. In this case, since we are dealing with money, I would suggest a 'double' data type or something comparable that will handle decimal values. (if you want to deal with only whole dollar amounts, be sure to let the user know)
2. Now that you have the user input, try using simple division to determine what denominations of money is to be 'returned' to the user. I would start testing with the largest denomination possible... then when that no longer works, then you can start trying lower denominations (based on real-life cashiering logic).
//This is your lowest denomination, so when we get to this point, we know we don't need to continue to calculate change with this loop.
while(change < 10)
{
//Test for your largest denomination first
if(amount / 100)
{
//adjust user inputed amount to withdraw
amount -= 100;
//keep a running counter of how many $100 bills ye' have issued thus far
hundreds++;
}
else if(amount / 50)
{
amount -= 50;
fifties++
}
...
...
...
etc etc.
cout << "You get " << hundreds << " x $100" <<endl;
cout << "You get " << fifties << " x $50"<<endl;
cout << "You get " << tens << " x $10" <<endl;
cout << "Remaining money: $" << amount;
This should get ye' pointed in some sort of direction.
This is untested/uncompiled …
What part of programming is specifically giving you difficulty? (please provide code with well-written question)
This is how I would write your block o' code:
#include<cstring>
for (int j=0;j<size;j++)
{
if(strcmp(a[j].n, name)
{
strcpy(a[j].n, name);
break;
}
}
The code I provided you is untested. Please let me know where any additional errors are with line number.
Some rules to remember:
you can use all boolean logic when at the 'char' level (comparing 'chars' to 'chars') you can also assign chars to other chars.
You cannot directly use boolean logic to directly compare c-strings to other c-strings (arrays to arrays)
You can assign an array pointer to an array pointer of the appropriate type (assign an array to an array pointer) if the appropriate amount of memory has been allocated.
Only if you are using <string> class objects can you compare to 'string' type variables using == equality test, or assign one string to another using the = assignment operator, or 'concantinate' (add to) an existing string using the += 'accumulation' operator.
I do believe our good friend adrianxw can help you with your desired console graphics and/or mouse needs:
I am lost as well.. without the assignment operator, it would make more sense because it would appear to use a constructor to initialize the main() object, just like one could initialize variable like this:
int x(10), y(20);
Since you are using c-strings (character arrays) you do not get the luxury of using the <string> class overloaded == equality test.
But what you do get is a bunch of <cstring> library functions that will allow you to handle your character arrays with great ease:
#include<cstring>
//instead of this
if((a[j]).n==name)
//try this
if(strcmp(a[j].n, name))
I am really not sure what is going on here. You are attempting to use a main() function like I've never seen it before. Therefore, this method you are using is more than likely unconventional.
To me, it seems like you are declaring an 'int' type variable called main (which I think is a c++ reserved keyword) and then attempting to initialize the poor int var with a bunch of non-int related gobbledygook.
I am not sure if you are trying to inline the main() function, or attempting to pass in a couple of arguments to the main() function (in which case you could consider using the argc argv[] command-line arguments) or if you are just trying to use a couple of default arguments (which I'm not sure if it is allowed for main()).
Anyway, the rest of the world is coding main() like this:
#include<iostream>
using namespace std;
int main()
{
cout << "Hello world!\n";
cin.get();
return 0;
}
Just looking briefly, I see one error on line #14 of ergasia.h:
#define FILENAME "_filenames.txt";
The string member capacity() is defined as:
Return size of allocated storage
Returns the size of the allocated storage space in the string object.Notice that the capacity is not necessarily equal to the number of characters that conform the content of the string (this can be obtained with members size or length), but the capacity of the allocated space, which is either equal or greater than this content size.
Notice also that this capacity does not suppose a limit to the length of the string. If more space is required to accomodate content in the string object, the capacity is automatically expanded, or can even be explicitly modified by calling member reserve.
The real limit on the size a string object can reach is returned by member max_size.
It is possible to speculate that different operating systems employ different memory management strategies. It is also possible to speculate that the same operating system will handle memory allocation differently among different machines. To go one step further, perhaps the same operating system will allocate memory differently at times on the same machine (depending on what processes are running, available memory etc.)
A lot of variables at play here to come up with a rock-solid answer. Since OS design is usually company-top-secret, perhaps we'll never know exactly how one OS handles memory allocation in comparison to others.
1. What specifically about the project is giving you problems?
2. Why did you take this course if you didn't want to make some sort of effort to learn the material..??!
Well, it certainly looks like you are on the right track.. well stated question and lots of code which shows effort on your part.
You've created all the necessary objects with the required attributes and functions. You've created the dynamic arrays of these objects as per the requirement. Your menu makes effective use of the switch/case structure; each case calling a specific function. Your code is self documenting and easy to follow. You effectively use the 'seperate compilation' by segregating your code into various header files and .cpp function definitions.
Let us know if you have any specific problems. I looked at your code for setting the student's name and didn't see any problems, maybe someone else will see it. (don't have a compiler on me' old laptop so I can't debug)
You are doing a lot of things right here.. have you taken a programming class before.??
You pose quite the intruiging and insightful question:
Binary Search Trees
Randomized Binary Search Trees
Balanced Binary Search Trees
my bad teehee
Here you create function specific variables that will be destroyed as soon as the function ends:
void calculateTotal(double heads, double tails)
{
double win = heads * 2;
double lose = tails * 1;
double total = heads - tails;
Therefore, you have no method of keeping record of how many heads and/or tails have appeared.
Couple of solutions: first, try saving the return value of the calculateTotal() function:
double = calculateTotal(double heads, double tails, int choice)
{
double win = heads * 2;
double lose = tails * 1;
//Beware, this could return a negative result which may confuse the user
double total = heads - tails;
...
...
...
if(choice == heads)
return win;
else return lose;
Another option would be just to declare a couple of variables (before int main(), or inside of int main(), doesn't matter) and pass them in by reference that the function can manipulate directly in memory:
void calculateTotal(double& heads, double& tails)
{
//Now you can perform operations directly on the heads/tails objects that reside in memory (as opposed to passing in 'copies' of the variables and then trying to save their return values which is obviously less efficient)
...
...
...
}
Also, remember that anytime you are keeping a 'running total', you might want to consider use the += "accumulation" operator.
That is the formula I was using Clinton Portis and it still came out to 1.7 x 10 to the 13th
This is what you posted:
I know height = distance * tan(angle) - (gravity * distance^2) /2 *( speed * cos(angle))^2
which is not the same as this:
#include<cmath>
height = (distance * tan(angle)) - (gravity * pow(distance, 2)) /2 * pow(speed * cos(angle), 2);
#include<cmath>
height = (distance * tan(angle)) - (gravity * pow(distance, 2)) /2 * pow(speed * cos(angle), 2);
Just do the opposite of what you are doing and it will rotate your 'cube' in the other direction.
Could someone please help me figure out what is wrong with my program?
Is there anything wrong with your program? I don't know. Does the program do something you don't want it to do? Do you have compilation errors? If so, what are they?
You declare: float celsius and float fahrenheit twice.. once outside of main(), and once inside of main. One one declaration of the variables are needed. Either before main() or inside of main(), doesn't really make a difference, but only once is needed.
Why is C++ so big?
That's what she said.
Of course you can always perform array operations on your string if you are not comfortable with using string class members:
#include<cctype>
string expression = "5+104-32/5";
string operators[10];
string terms[20];
int term_counter=0;
int op_counter=0;
for(int i=0; i<expression.size(); i++)
{
if(expression[i] == '+' || expression[i] == '-' ||
expression[i] == '*' || expression[i] == '/')
{
//extract all operators (in sequential order)
operators[op_counter] = expresssion[i];
op_counter++;
term_counter++;
}
else if(isdigit(expression[i]))
{
//Extract terms into individial 'string' containers
terms[term_counter] += expression[i];
}
}
also i have to make a simlple calculator.. with only one operation at a time.. i.e only 5+4 at a time and not 5+4*3 bcoz dat will involve precedence rules...
All of the above code will work for what you are asking.
Btw, you'll also need this function which will allow you to set the cursor position to anywhere on the dos console.
#include <windows.h>
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
You'll probably become much more interested in this when it comes time to draw ye' circle.
Also, there is an error in the draw_rect() function on line #15. Instead of set() the correct function name is setw() from the <iomanip> library. As with all my code, it is not tested and may contain simple easy to fix errors, and is only intended to help others get pointed in the right direction.
Here is the pseudo-code for what you wish to accomplish:
1. create an array of integers that will be large enough to handle user input. This array will hold all of the 'n' rectangle data
2. using a loop, continuously prompt the user for coordinates until until such time user no longer wants to input coordinates
3. In your loop, you will have to test user input to see if it meets the "n must be divisible by 3" critera:
if(!numbers[i]%3){ cout << "\a\nError! Number must be divisible by 3!";}
4. At this point, you have an array of integers, all of which are divisible by 3. Your next requirement is to sort the user input.
#include<algorithm>
sort(&numbers[0], &number[42]);
5. You now have an aray of integers (all of which are divisible by 3) sorted to ascending order. Your next task now is: "the first two numbers are used to create a rectangle(if not equal) or a square( if they are equal). Since we are only allowed to use 2 integer values to draw our square/rectangle, I will assume the integer values will represent 'side lengths' of the objects we wish to draw. As per your requirement, the first two integers excracted from the array will be used to draw a square/rectangle:
#include<iomanip>
void draw_rect(int& topbottom, int& sides)
{
for(int i=0; i<topbottom; i++)
{
//draw top
} cout << '*';
cout << endl;
for(int i=0; i<sides; i++)
{
//draw sides
cout << '*' << …
This is a common mistake whilst performing tests using boolean logic; there is a distinct difference between the '=' assignment operator and the '==' equality test. (the '=' assignment operator should never be used to perform boolean tests)