I have another homework assignment that is asking:
Write a program that asks the user for points in a graph.
Determine what quadrant the points are in and display an appropriate message.
Ask if the use wants to continue, and if the answer is "yes" then continue, otherwise do not. Count how many points were in each quadrant and display the count at the end. If the point is on either axis, display a message and do not count it.
a while loop must be used in this to have keep asking for points until you say no. I really am only have a problem setting up the while loop to actually work, other than that I am pretty sure I can make everything else work. i dont know anything fancy just basic stuff. Any help would be great. here is the code i have so far:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x, y, counter=1, quad1=0, quad2, quad3, quad4;
string answer, Yes, No;
cout << "Please enter the x coordinate: ";
cin >> x;
cout << "Please enter the y coordinate: ";
cin >> y;
while (answer == Yes)
{
if ((x > 0)&&(y > 0))
{
cout << "Quadrant I" << endl;
cout << "Do you want to continue (\"Yes\"" << " or \"No\"" << ")? ";
cin >> answer;
}
}
}
#include <stdio.h>
#include <iostream>
usingnamespace std;
int main()
{
int x, y;
char answer('y');
do {
printf("Please enter the x coordinate: \n"); //printf() is just my personal preference here
cin >> x;
printf("Please enter the y coordinate: \n");
cin >> y;
if ((x > 0) && (y > 0))
printf("Quadrant I\n");
if ((x < 0) && (y > 0))
printf("Quadrant II\n");
if ((x < 0) && (y < 0))
printf("Quadrant III\n");
if ((x > 0) && (y < 0))
printf("Quadrant IV\n");
printf("Do you want to continue ( 'y' or 'n'? \n");
cin >> answer;
} while (answer == 'y' || answer == 'Y');
return 0;
}
you could also avoid all of the if statement checks by making all of the if statements have continue statements, and then the yes or no input at the beginning of the loop (which would be a while(true) loop), when the input is taken at the beginning of the loop, an if statement could lead to a break statement when they entered not a 'y' char.