Hi all.
A while back I'd posted regarding a do-while routine, using switch.
It appears that my main is working, and my switch.... it just keeps looping around my main menu.
I'm not entirely clear on why either.
Here is the code.
(One responder to a previous post told me that my indenting sucked, I've done a preview, and it looked good when I posted. It if screws up, please accept my apologies. I did try...)

# include "stdafx.h"
# include <iostream>
# include <cmath>
# include <xutility>
# include <stdlib.h>
# include <cctype>
# include <conio.h>
# define PI 3.1415926535898

using namespace std;
char ch; 
//I've tried both int, and char, as well as with 
//single quotes within my switch, for char ch and without 
//the single quotes for int ch.

int main(int argc, _TCHAR* argv[])
{
do 
{
cout << "Copyright 2001, Welcome to the Angle Finder Program." << endl;
cout << "This program is designed to take only numeric values." << endl;
cout << "Make certain you only input numbers. Otherwise it will exit." << endl;
cout << " Please choose:  1 for the Hip/Valley Angle. "<< endl;
	cout << "2 for the Cricket Valley Angle. " << endl;
	cout << "3 for the Ridge Angle "<< endl;
	cout << "0 to exit. "<< endl;

cin >> ch;
switch (ch)
{ 
case '1' :  int HipValley(int& Rise1, int& Rise2, double& Eave, float& a); 
// this is the Hip/Valley choice.
break;
case '2' : int CricketValley(int& Rise1, int& Rise2, double& Eave, float& a, float& Width); 
// this is the cricket valley choice.
break;
case '3' : int RidgeAngle(int& Rise1, int& Rise2); 
//this is the Ridge Angle choice.
break;
default : return 0; // this will end the routine.
}
}while (ch != 27);
return 0;
}

I get no errors, it compiles fine, but it just loops the main menu over and over until I enter 0.

Recommended Answers

All 3 Replies

case '1' : int HipValley(int& Rise1, int& Rise2, double& Eave, float& a);
what is this?
int HipValley(int& Rise1, int& Rise2, double& Eave, float& a);

is this a function call?

If so no need to specify the return type.
You can use
HipValley( Rise1, Rise2, Eave, a);
to call a function.
also change other two.

When you are calling a function, no need to specify the return type as well as data type of arguements.

Yeah, you didn't even specify if
case 1: ........ // is a function or not?

if yes, then you shouldn't write the type of the parameters
as RenjithVR said

if it is not a function then!! what is it?

They were functions.
And that was the fix.
Thank you.

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.