I am new to C++ and I am having problems with my code as you may imagine. As a newbie, I am creating an application in which converts celsius to fahrenheit and vice versa. The application has to ask what the user wants. I set up the application to run but the problem is that I don't know what else to do to go from a function to a switch. I am stuck on main, where I declare getMenuSelection and try to move onto the switch.I only went as far as putting the case: F just as a testing method. If any programming masters can help, I would appreciate it, thanks. Below is my code;

#include <iostream>                   
#include <cmath>
#include <iomanip>
#include <stdio.h>

using namespace std;

void displayMenu(void)
	{// Function displayMenu() 

		cout << "Please enter one of the following choices to begin:" << endl;
		cout << "\n\t F or f => Convert from Celcius to Fahrenheit.";
		cout << "\n\t C or c => Convert from Fahrenheit to Celcius.";
		cout << "\n\t Q or q => Quit" << endl;
	}
char getMenuSelection(char fahcel)
	{
		char fahCel;

		cout << "Your entered:";
		cin >> fahCel;
		return 0;
	}
double getStartEndAndIncrement(double statemp, double endtemp, double incr)
	{
		double staTemp,
			endTemp,
			inc;

		cout << "Enter starting temperature, ending temperature, and increment value: " << "\n" << endl;
		cin >> staTemp >> endTemp >> inc;
		return 0;
	}
	
double cToF(double staTemp, double endTemp)
	{
		double statemp,
			endtemp,
			celsius = 0,
			fahrenheit = 0;
		
		statemp = celsius,
		endtemp = celsius;

		fahrenheit = celsius * 9.0/5.0 + 32;       // Formula Cel to Fah
		return 0;
	}
double fToC(double staTemp, double endTemp)
	{
	 double statemp,
		 endtemp,
		 celsius = 0,
		 fahrenheit = 0;
		
	    statemp = fahrenheit,
		endtemp = fahrenheit;

		celsius = fahrenheit * 9.0/5.0 - 32;       // Formulas Fah to Cel
		return 0;
	}

double displayCToFTable(double staTemp, double endTemp, double inc)
{
   double statemp,
		  endtemp,
		  incr = 0,
		  result;
		  
	      statemp = 0,
		  endtemp = 0;
		
	while (-1000 >= statemp && endtemp <= 1000);
		{//Start while loop
        printf("%6.2f degrees C = %6.2f degrees F\n",
            statemp, (statemp + 32.0) * 5.0 / 9.0);
		if (statemp > endtemp)
				cout << "Starting temperature higher than ending temperature!!" << endl;
		else 
				result = statemp + incr;

		}//End while loop
		return 0;
}
double displayFToCTable(double staTemp, double endTemp, double inc)
{
   double statemp,
		  endtemp,
		  incr = 0,
		  result;
		  
	      statemp = 0,
		  endtemp = 0;
		
	while (-1000 >= statemp && endtemp <= 1000);
		{//Start while loop
        printf("%6.2f degrees F = %6.2f degrees C\n",
            statemp, (statemp - 32.0) * 5.0 / 9.0);
		if (statemp > endtemp)
				cout << "Starting temperature higher than ending temperature!!" << endl;
			
		else 
			
				result = statemp + incr;
		}//End while loop
		return 0;
}
char fahCel;

int main()
{
	double fahrenheit = 0,
	   celsius = 0;
	char choice;

	cout << "This is a conversion program that converts Celsius to Fahrenheit and vice versa. " << endl;
    
	displayMenu();
	
	choice = getMenuSelection(fahCel);
	
	switch (choice)
	{// Start Switch 
	case 'f':
	case 'F':
		cout << "Converting from Celsius to Fahrenheit. " << endl << "\n" << endl;

		double getStartEndAndIncrement(double statemp, double endtemp, double incr);
			
		double cToF(double staTemp, double endTemp);
			
		double displayCToFTable(double staTemp, double endTemp, double inc);
			

	}// Ending brace for Switch

	cin.ignore(2);
		return 0;
}// Ending brace for Main

Recommended Answers

All 4 Replies

so, first of all (this seems like a very large program for at pretty small calculation?) you have misunderstood how input/output works in C++.
You need to define your functions along the line:

ouputType funcName(inputs){


return outputVal;
}

So, for instance, you second one, "getSelection" should be

char getSelection()
{
		char fahCel;
 
		cout << "Your entered:";
		cin >> fahCel;
		return fahCel;
}

That should go some way in clearing up your problems.

Your basic problem stems from not knowing what you need the program to do. For example, in your description you say:

I am creating an application in which converts celsius to fahrenheit and vice versa.

All well and good - as far as it goes. Then you continue with:

The application has to ask what the user wants.

Well, I want a pizza. No? How about... :icon_wink:

You have to know what you are going to give him, and ask for the information you need to get that gift to him. So the first thing is a C to F conversion. Single temperature? A range? When you give the answer do you ask for another or do you exit with a job well done?

Once you figure all that out, then you start designing the program. But on paper only!
Start with:
1) what do I ask for and how does it look to the user.
2) when I've calculated the answer, how do I present the answer to the user.
3) with the stuff from 1, how do I get to step 2?

Now you're ready to code just the initial input (step 1). As you do that, print the responses to the screen as if they are the output. Just to be sure the input is completely working.

Start with that...

And please format your code better. There is too much indentation and it's also inconsistent.

Parallel Arrays Assignment

The presidential election for the student council of your local university will be held soon. For reasons related to confidentiality, the chair of the election committee wants to computerize the voting. The chair is looking for someone to write a program to analyze the data and report the winner. Let us write a program to help the election committee.

The university has four major divisions, and each division has several departments. For the purpose of the election, the four divisions are labeled as Region 1, Region 2, Region 3, and Region 4. Each department in each division manages its own voting process and directly reports the votes received by each candidate to the election committee. The voting is reported in the following form:

Candidate-name region# number_of_votes_for this_candidate

The presidential election for the student council of your local university will be held soon. For reasons related to confidentiality, the chair of the election committee wants to computerize the voting. The chair is looking for someone to write a program to analyze the data and report the winner. Let us write a program to help the election committee.

The university has four major divisions, and each division has several departments. For the purpose of the election, the four divisions are labeled as Region 1, Region 2, Region 3, and Region 4. Each department in each division manages its own voting process and directly reports the votes received by each candidate to the election committee. The voting is reported in the following form:

Candidate-name region# number_of_votes_for this_candidate

Below is input specification:
===============================================================
Name Region 1 Region 2 Region 3 Region 4
------ ---------- ---------- ----------- -----------
Balto 0 0 0 272
Doc 25 71 156 97
Sally 38 88 5 101
Raju 115 75 20 33
Rema 49 71 18 0


The election committee wants the output in the following tabular form:

---------------------- Election Results ----------------------

Candidate Votes
Name Region 1 Region 2 Region 3 Region 4 Total
------------ ---------- ---------- ----------- ----------- -------
Balto 0 0 0 272 272
Doc 25 71 156 97 349
Sally 38 88 5 101 ?
Raju 115 75 20 33 ?
Rema 49 71 18 0 ?

Winner: ??? Votes Received: ???
Total votes polled: ???


The election committee wants the output in the following tabular form:

---------------------- Election Results ----------------------

Candidate Votes
Name Region 1 Region 2 Region 3 Region 4 Total
------------ ---------- ---------- ----------- ----------- -------
Balto 0 0 0 272 272
Doc 25 71 156 97 349
Sally 38 88 5 101 ?
Raju 115 75 20 33 ?
Rema 49 71 18 0 ?

Winner: ??? Votes Received: ???
Total votes polled: ???

Version 1
Parallel Array assignment link to access the assignment. Code, compile, link, and execute a C++ program using the given input specification to produce the output specification.

Version 2
Parallel Array assignment link to access the assignment. Code, compile, link, and execute a C++ program using the given input specification to produce a sorted output specification.

I need 2 programs in C++. Version one with array input, output and version two with input, sorted output. Please help me with this assignment. Really appreciate if anybody could help with the above program.

[boilerplate_help_info]

Posing requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]To [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
[/list]
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.

[/boilerplate_help_info]

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.