i want to design a program of temperature converter.
Here is my pseudo code
[code]
Pseudo-code representation
1.0 START.
2.0 DISPLAY MENU :Please choose the type of converter
1.Celsius to Fahrenheit converter
2. Fahrenheit to Celsius converter
3.0 INPUT Type of converter: 1 OR 2
4.0 IF (1.Celsius to Fahrenheit converter)
5.0 READ the ℃_Celsius
6.0 ℉_Fahrenheit = 32+℃_Celsius (180.0/100.0)
7.0 PRINT ℃_Celsius =℉_Fahrenheit
8.0 END IF
9.0 IF NOT
10.0 IF (Fahrenheit to Celsius converter)
11.0 READ the ℉_Fahrenheit
12.0 ℃_Celsius =(℉_Fahrenheit-32)(100.0/180.0)
13.0 PRINT ℉_Fahrenheit= ℃_Celsius
14.0 END IF NOT
15.0 DISPLAY MENU Continue to convert or not
16.0 IF( Continue)
17.0 RETURN to step 2.0
18.0 IF NOT
19.0 END
About step 17, what function should i use to return to step 2.0?
please state more specific. I already complete the whole program except the command to make it go back to step 2.0.
#include <iostream>
#include <stdio.h>
#include <conio.h>
using namespace std;
int main()
{
float temp,ctemp;//temp =celsius, ctemp=fahrenheit
int ch,tch;//ch=choice of converter, tch = choice of continue
void c1rscr();
cout<<"Temperature Conversion Menu\n";
cout<<"\t1. Fahrenheit to Celsius\n";
cout<<"\t2. Celsius to Fahrenheit\n";
cout<<"Enter your choice(1/2):";
scanf("%d",&ch);
if(ch==1)
{
printf("Enter Temperature in Fahrenheit:");
scanf("%f",&ctemp);
temp=(ctemp-32)/1.8;
printf("Temperature in celsius is%f",temp);
} else
if(ch==2)
{
printf("Enter Temperature in Celsius");
scanf("%f",temp);
ctemp=(1.8*temp)+32;
printf("Temperature in Fahrenheit is %f",ctemp);
} else
{
printf("Wrong choice........!!");
return 11 ;
}
printf("\n");
printf("Continue to convert or not:\n");
printf("\t1.continue \n");
printf("\t2.do not continue \n");
cout<<"Enter your choice(1/2):";
scanf("%d",&tch);
Lines [45, 49] can be removed completely.
Line 9 declares an unused function and can be removed.
Use std::cout and std::cin consistently. Do not mix C and C++-style IO. This can result in bugs on some nonconforming implementations.
If you choose to use or mix C-style IO instead of C++-style IO, do not include the C header file, but rather the C++ extensionless version, <cstdio> instead of <stdio.h>.
Do not include <conio.h>. It doesn't exist as a part of standard C++.
Properly indent your code.
Use better names than temp, ctemp, and so on. Why not fahrenheit and celsius? choice, to_continue?
Do not import the entire standard namespace. I just posted something about it: http://www.cplusplus.com/forum/beginner/209087/#msg984016