// This is a program that displays the choice the user picks using a Switch Statement

#include <iostream>
#include <string>

using namespace std;

int main()
{
	// Underneath A switch program that shows the user his input choice 

	string word1 = "Achieve";

	cout << "Welcome to Your AccuWeather Report Screen." << endl;
	cout << endl;
	cout << "Your choices are listed at the bottom." << endl;
	cout << endl;
	cout << "Choose what you want to view" << endl;
	cout << endl;
	cout << "Number 1 - Temperature outside right now" << endl;
	cout << endl;
	cout << "Number 2 - Stock Price of the day" << endl;
	cout << endl;
	cout << "Number 3 - Word of the day" << endl;
	cout << endl;
	cout << "Number 4 - Check the Last account that was opened" << endl;
	cout << endl;

	int Answer;
	cout << "Answer : ";
	cin >> Answer;
	cout << endl;

	// Underneath Shows the outcome of the operators number input

	switch (Answer)
	{
	case 1:
		cout << "It's a nice, sunny, 85 degree warm day today. We have a nice chilling breeze coming in from the north today, so I advise people to go outside and enjoy the day" << endl;
		cout << endl;
		break;

	case 2:
		cout << "Stock Price as of 2 pm today is $3.45 per share." << endl;
		cout << endl;
		break;

	case 3: 
		cout << "Our 'Word of the Day' is :  " << word1 << endl;
		cout << endl;
		break;

	case 4:
		cout << "Last Account Opened: Mr. Jones.  " << endl;
		cout << endl;
		cout << "Reason: Selling his cat on Craigslist." << endl;
		cout << endl;


	// if user inputs a wrong choice, I prompted them 

	default:
		cout << " What did you type??" << endl;

	// Code used to generate the try again

	char again = 'y', n = 'n';
	while ((again == 'y') && (n == 'n'))
	{
		cout << "Try again? (y/n) ";
		cin >> again;
		cout << endl;
		cout << endl;
		cout << endl;

	  // Gives you your options again

		cout << "Here are your choices again " << endl;
		cout << endl;
		cout << main();
		if (cin >> n)
		{
			cout << "Good Bye" << endl;
		}
	}
	}

	system("PAUSE");
	return 0;
}

I need the program to do this >>>>>> If the user selected n in the try again method, that he would be prompted good bye and then the program would end.

can someone show me how without using their jedi mind powers??? a lot would be appreciated

Member Avatar for danb737

You should wrap your menu + switch statement in a do while loop, so from line 13 to line 75. The condition for the while would be that (again == 'y'). Btw, I don't see much use for the variable n.

In addition to the post above, line 80 is confusing.

cout << main();

I suppose it might work to call main() from your program (but it's not a good idea. There are better solutions), but what are you trying to do with the "cout" part of that line?

try this
1- declare a bool variable(flag) and assign it to false.
2- use a while loop and put your switch statement in it , your loop condition is (!flag).
3- add a new case to your switch statement case 5 : which exist from the program
in this case you change the flag to true which will exit the switch statement

commented: i wish u showed me an example but it'll have to do. +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.