I need help with c++ temp converter

i need help calling my data and making my output correct. any help wou

Page 1 of 1

7 Replies - 1552 Views - Last Post: 30 November 2008 - 02:17 PM Rate Topic: -----

#1 immortal_reiku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 08

I need help with c++ temp converter

Posted 29 November 2008 - 12:16 PM

#include <iostream>

using namespace std;
 int getStartEndAndIncrement(double x, stop, increment, a, b, c);
int main(double x, stop, increment, a, b, c)
{
   
  
   int sourceTemperature, answer, menuChoice;    
   int a;     
   
   cout<< "\nPlease choose one of the following:\n";
   cout<< "   1. Farenheit to Celsius\n";
   cout<< "   2. Celsius to Farenheit\n";
   cout<< "   3. Exit from program\n";
   cout<< "Your choice: ";
   cin>> menuChoice;       // Read in the desired menu choice
   
   // Process menu option
   if (menuChoice == 3) {     // If menu choice was 3, exit from program
      exit( 0);               // normal program termination
   }
   if (menuChoice > 3) {		// Abort on invalid menu options
      cout<< "Invalid menu option entered.   Aborting...\n";
      exit( -1);              // Abnormal program termination
   }
          
   //Prompt for temperature
   cout<< "Please enter the temperature: ";
   cin>> sourceTemperature;
   
   //cCalculate correct answer depending on menu selection
   if (menuChoice == 1) {		 	//F. to C.
      answer = (sourceTemperature - 32) * 5.0/9.0;
   }
   else if (menuChoice == 2)  {     	// C. to F.		
      answer = sourceTemperature * 9.0/5.0 + 32;
   }	
   else {		
      cout<< "SInvalid menuChoice ...\n";
      exit( -1);	// leave the program
   }
          
	
int getStartEndAndIncrement(int i);

  {double x, stop, increment, a, b, c;

cout<< "Please enter start.\n";
cin >>a;
cout<< "Please enter stop.\n";
cin >>b;
cout<< "Please enter incrementation.\n";
cin >>c;

x = a; 
stop = b; 
increment = c; 

return  x, stop, increment, a, b, c;
cout<<"C\tF"<<endl; //output table heading
for ( ; x<=stop; x += increment) {

    cout<<x<<"\t"<<(1.8*x+32.0)<<endl; // table values


}

}
 return 0;

  

}


*edit: Please use code tags in the future, thanks! :code:



//and my output should look like the attachment I made. I thank anyone ahead of time for helping me. Attached File  conversionoutput.bmp (870.93K)
Number of downloads: 69

This post has been edited by Martyr2: 29 November 2008 - 12:33 PM


Is This A Good Question/Topic? 0
  • +

Replies To: I need help with c++ temp converter

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4332
  • View blog
  • Posts: 12,126
  • Joined: 18-April 07

Re: I need help with c++ temp converter

Posted 29 November 2008 - 12:32 PM

You have a lot of things wrong here. So many in fact that I would have to rewrite the entire program for you which is a bit beyond the scope of what we do here.

1) First of all, you don't pass parameters like that to main. Typically you have just int main(). If you want to pass arguments to the program (which I don't think you want to do here) you would use something like int main(int argc, char *argv[]).

2) You define a prototype for your function getStartEndAndIncrement but you forgot that you must specify data types to each parameter. You do it with x by saying it is "double" but you have to add the data types for the others. It isn't like variable definitions where it will make each one double. It must also match the prototype you put up top. So if you have 3 parameters of type double, your function should also have three parameters of type double.

3) Also related to your function getStartEndAndIncrement, you "attempt" to create this but you did it inside of main. Each function is separate from one another. So you have main(), closed by curly braces and THEN your other function. Check out how you setup functions in your book or on the web.

4) return statements from functions return 1 value, you cannot list multiple variables to return. Now you could setup an array, put your answers in the array and return the array, but more likely if you need to return multiple values then you pass your parameters by pointer or reference. Look those terms up if you need more help with those.

Lastly, please put code in code tags in the future which will make our job a bit easier.

So work on those items there and present some code that has fixed up a bit syntax and we can then see where your logic is going wrong.

Good luck to you. :)
Was This Post Helpful? 0
  • +
  • -

#3 immortal_reiku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 08

Re: I need help with c++ temp converter

Posted 29 November 2008 - 04:23 PM

Thanks I will get to work on it immediately.
Was This Post Helpful? 0
  • +
  • -

#4 immortal_reiku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 08

Re: I need help with c++ temp converter

Posted 29 November 2008 - 04:37 PM

View Postimmortal_reiku, on 29 Nov, 2008 - 03:23 PM, said:

Thanks I will get to work on it immediately.

#include <iostream>







using namespace std;
int getStartEndAndIncrement(int x,int stop,int increment);
int main()
{


int sourceTemperature, answer, menuChoice;
int a;

cout<< "\nPlease choose one of the following:\n";
cout<< " 1. Farenheit to Celsius\n";
cout<< " 2. Celsius to Farenheit\n";
cout<< " 3. Exit from program\n";
cout<< "Your choice: ";
cin>> menuChoice; // Read in the desired menu choice

// Process menu option
if (menuChoice == 3) { // If menu choice was 3, exit from program
exit( 0); // normal program termination
}
if (menuChoice > 3) { // Abort on invalid menu options
cout<< "Invalid menu option entered. Aborting...\n";
exit( -1); // Abnormal program termination
}

//Prompt for temperature
cout<< "Please enter the temperature: ";
cin>> sourceTemperature;

//cCalculate correct answer depending on menu selection
if (menuChoice == 1) { //F. to C.
answer = (sourceTemperature - 32) * 5.0/9.0;
}
else if (menuChoice == 2) { // C. to F.
answer = sourceTemperature * 9.0/5.0 + 32;
}
else {
cout<< "SInvalid menuChoice ...\n";
exit( -1); // leave the program
}
return 0;
}

int getStartEndAndIncrement();

{
int x,int stop,int increment;

cout<< "Please enter start.\n";
cin >>a;
cout<< "Please enter stop.\n";
cin >>b;
cout<< "Please enter incrementation.\n";
cin >>c;

x = a;
stop = b;
increment = c;

cout<<"C\tF"<<endl; //output table heading
for ( ; x<=stop; x += increment) {

cout<<x<<"\t"<<(1.8*x+32.0)<<endl; // table values

}






This is what I got if you need what the output looks like get it from the post above. I am having a real hard time with this and I still get errors. Anything you could do to help me understand the call by functions and how to make the output table that is in the image. I'm new to c++ and am having a difficulty in programming.
Was This Post Helpful? 0
  • +
  • -

#5 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I need help with c++ temp converter

Posted 30 November 2008 - 05:17 AM

1 - Please post any code between the code tags as set out in posting rule 3.

2 - I have removed the semicolon ";" from the end of the function declaration so we can get some useful errors for you to look at.

Here is your code laid out so it as least somewhat readable:
#include <iostream>
using namespace std;
int getStartEndAndIncrement(int x,int stop,int increment);
int main()
{
	int sourceTemperature, answer, menuChoice;
	int a;

	cout<< "\nPlease choose one of the following:\n";
	cout<< " 1. Farenheit to Celsius\n";
	cout<< " 2. Celsius to Farenheit\n";
	cout<< " 3. Exit from program\n";
	cout<< "Your choice: ";
	cin>> menuChoice; // Read in the desired menu choice

	// Process menu option
	if (menuChoice == 3) { // If menu choice was 3, exit from program
		exit( 0); // normal program termination
	}
	
	if (menuChoice > 3) { // Abort on invalid menu options
		cout<< "Invalid menu option entered. Aborting...\n";
		exit( -1); // Abnormal program termination
	}

	//Prompt for temperature
	cout<< "Please enter the temperature: ";
	cin>> sourceTemperature;

	//cCalculate correct answer depending on menu selection
	if (menuChoice == 1) { //F. to C.
		answer = (sourceTemperature - 32) * 5.0/9.0;
	}
	else if (menuChoice == 2) { // C. to F.
		answer = sourceTemperature * 9.0/5.0 + 32;
	}
	else {
		cout<< "SInvalid menuChoice ...\n";
		exit( -1); // leave the program
	}
		
	return 0;
}

// NOTE THAT I DELETED THE SEMICOLON FROM
//    THE END OF THE FOLLOWING LINE FOR YOU
int getStartEndAndIncrement()
{
	int x,int stop,int increment;

	cout<< "Please enter start.\n";
	cin >>a;
	cout<< "Please enter stop.\n";
	cin >>b;
	cout<< "Please enter incrementation.\n";
	cin >>c;

	x = a;
	stop = b;
	increment = c;

	cout<<"C\tF"<<endl; //output table heading
	for ( ; x<=stop; x += increment) {
		cout<<x<<"\t"<<(1.8*x+32.0)<<endl; // table values
}



and here are the compiler errors you still have:
dic.cpp: In function ‘int main()’:
dic.cpp:7: warning: unused variable ‘a’
dic.cpp: In function ‘int getStartEndAndIncrement()’:
dic.cpp:45: error: expected unqualified-id before ‘int’
dic.cpp:48: error: ‘a’ was not declared in this scope
dic.cpp:50: error: ‘b’ was not declared in this scope
dic.cpp:52: error: ‘c’ was not declared in this scope
dic.cpp:55: error: ‘stop’ was not declared in this scope
dic.cpp:56: error: ‘increment’ was not declared in this scope
dic.cpp:62: error: expected `}' at end of input
dic.cpp:62: warning: control reaches end of non-void function
----

But more than anything you need to:
1 - get your textbook out and look at each line against the examples in the book and see what you have done that is wrong; and
2 - look at all your uses of "{" and ensure there is a matching "}" where you expect it to be.

Your code is just not been put together carefully enough for you to get through the typing errors and syntax errors to see what, if any, logic errors you may have.

Slow, careful and painstakig work for less than an hour should see you a lot further down the path.
Was This Post Helpful? 1
  • +
  • -

#6 immortal_reiku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 08

Re: I need help with c++ temp converter

Posted 30 November 2008 - 09:05 AM

#include <iostream>







using namespace std;
int getStartEndAndIncrement(int x,int stop,int increment);
int main()
{


int x,int stop,int increment;
double b, c, d;
int sourceTemperature, answer, menuChoice;
double answer;

cout<< "\nTemperature Converter\n";
cout<< "\nPlease choose one of the following:\n";
cout<< " 1. Farenheit to Celsius\n";
cout<< " 2. Celsius to Farenheit\n";
cout<< " 3. Exit from program\n";
cout<< "Your choice: ";
cin>> menuChoice; // Read in the desired menu choice

// Process menu option
if (menuChoice == 3) { // If menu choice was 3, exit from program
exit( 0); // normal program termination
}
if (menuChoice > 3) { // Abort on invalid menu options
cout<< "Invalid menu option entered. Aborting...\n";
exit( -1); // Abnormal program termination
}

//Prompt for temperature
cout<< "Please enter the temperature: ";
cin>> sourceTemperature;

//cCalculate correct answer depending on menu selection
if (menuChoice == 1) { //F. to C.
answer = (sourceTemperature - 32) * 5.0/9.0;
}
else if (menuChoice == 2) { // C. to F.
answer = sourceTemperature * 9.0/5.0 + 32;
}
else {
cout<< "SInvalid menuChoice ...\n";
exit( -1); // leave the program
}




cout<< "Please enter start.\n";
cin >>b;
cout<< "Please enter stop.\n";
cin >>c;
cout<< "Please enter incrementation.\n";
cin >>d;

x = b;
stop = c;
increment = d;

cout<<"Table of Celcius and Farenheit in degrees \n\n"<<endl; //output table heading
"Degrees Degrees\n"
"Celcius Fahrenheit";
sourceTemperature=-20;

for ( i=1; i <=6; i++)
{


cout<<answer<<"\t"<<(1.8*x+32.0)<<endl; // table values




return 0;
}





This is what I got now. I v=can;t seem to get rid of my errors which are
1>------ Build started: Project: Ilab05CKarcher, Configuration: Debug Win32 ------
1>Compiling...
1>Ilab05CKarcher.cpp
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(15) : error C2062: type 'int' unexpected
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(18) : error C2371: 'answer' : redefinition; different basic types
1> c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(17) : see declaration of 'answer'
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(43) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(46) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(63) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(64) : error C2065: 'stop' : undeclared identifier
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(65) : error C2065: 'increment' : undeclared identifier
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(72) : error C2065: 'i' : undeclared identifier
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(76) : error C2088: '<<' : illegal for class
1>c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(92) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\immortal_reiku\documents\visual studio 2005\projects\ilab05ckarcher\ilab05ckarcher\ilab05ckarcher.cpp(12)' was matched
1>Build log was saved at "file://c:\Users\Immortal_Reiku\Documents\Visual Studio 2005\Projects\Ilab05CKarcher\Ilab05CKarcher\Debug\BuildLog.htm"
1>Ilab05CKarcher - 7 error(s), 3 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is what the output is supposed to be
Was This Post Helpful? 0
  • +
  • -

#7 immortal_reiku  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-November 08

Re: I need help with c++ temp converter

Posted 30 November 2008 - 10:08 AM

#include <iostream>
#include <iomanip>







using namespace std;
int getStartEndAndIncrement(int x,int stop,int increment);
int main()
{


int x,stop,increment;
double b, c, d;
int sourceTemperature, answer, menuChoice;

cout<< "\nTemperature Converter\n";
cout<< "\nPlease choose one of the following:\n";
cout<< " 1. Farenheit to Celsius\n";
cout<< " 2. Celsius to Farenheit\n";
cout<< " 3. Exit from program\n";
cout<< "Your choice: ";
cin>> menuChoice; // Read in the desired menu choice

// Process menu option
if (menuChoice == 3) { // If menu choice was 3, exit from program
exit( 0); // normal program termination
}
if (menuChoice > 3) { // Abort on invalid menu options
cout<< "Invalid menu option entered. Aborting...\n";
exit( -1); // Abnormal program termination
}

//Prompt for temperature
cout<< "Please enter the temperature: ";
cin>> sourceTemperature;

//cCalculate correct answer depending on menu selection
if (menuChoice == 1) { //F. to C.
answer = (sourceTemperature - 32) * 5.0/9.0;
}
else if (menuChoice == 2) { // C. to F.
answer = sourceTemperature * 9.0/5.0 + 32;
}
else {
cout<< "SInvalid menuChoice ...\n";
exit( -1); // leave the program
}




cout<< "Please enter start.\n";
cin >>b;
cout<< "Please enter stop.\n";
cin >>c;
cout<< "Please enter incrementation.\n";
cin >>d;

x = b;
stop = c;
increment = d;
int i;

cout<<"Table of Celcius and Farenheit in degrees \n\n"<<endl; //output table heading
"Degrees Degrees\n"
"Celcius Fahrenheit";
sourceTemperature=-20;

for ( i=1; i <=6; i++)
{


cout<<answer<<"\t"<<(1.8*x+32.0)<<endl; // table values
cout<< setw(12)<<sourceTemperature<<setw(19)<<answer<<endl;
}



return 0;
}







// I think I am really close If any one can show me how to clean up my output it would be greatly appreciated. I have six hours remaining. Wish me luck.
Was This Post Helpful? 0
  • +
  • -

#8 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: I need help with c++ temp converter

Posted 30 November 2008 - 02:17 PM

You really need to post your code wrapped in the code tags
:code:
if people are going to help you.

Posting without the code tags just makes things hard enough that people pass on to the next question.

This post has been edited by janotte: 30 November 2008 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1