Need help fixings bugs/errors

As you can tell, I'm trying to convert inches to cm, or cm to inches, depending on the input from the user. I'm new to using char and wondering how I'm suppose to write this code. Thanks for the help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//inches_conversion.cpp

#include <iostream.h>
#include <conio.h>
#include <iomanip.h>

           
   int main()
           
   
   {
   
      int inches, cm; //inches & centimeters
      char type, ans; //type of conversion & answer to continue/stop
      float org, converted; //orginal & converted answer
      ans=1;
   
      while (ans==1)
      {
         cout<<"\nType C to convert to Centimeters or I to convert to Inches: ";
         cin>>type;
      
         if (type=='c' | type=='C')
         {
            cout<<"\nEnter the number of inches to be coverted: " << endl;
            cin>>inches;
            cout<<inches<<" converts to: " (inches*2.54)<<" centimeters.";
         }
         else if ('i' | 'I')
         {
            cout<<"\nEnter the number of centimeters to be converted: " << endl;
            cin>>cm;
            cout<<cm<<" converts to: "<< (cm/1)<<" inches."<<endl;
         }
      
         getch();
         cout<<"Do you want to make another conversion? (y/n): ";
         cin>>ans;
         cout<<endl;
      }
   
      return 0;
   
   }
23
24
25
26
27
28
29
30
if (type == 'c' || type == 'C') // Two '|'
{
    // ...
}
else if (type == 'i' || type == 'I') // You still have to write the whole thing out
{
    // ...
}

Alternatively, use std::toupper or std::tolower (in <cctype>) so that you don't need to compare both lowercase and uppercase.
@long double main,

I entered and fixed my code based off of your reply. My errors for those specific lines are gone except for one. In this line, cout<<inches<<" converts to: " (inches*2.54)<<" centimeters."; I am getting a "call of nonfunction in function main, error. Why am I getting this?

EDIT: Never mind, I fixed it. I'm dumb. :)
Last edited on
cout<<inches<<" converts to: " << (inches*2.54)<<" centimeters.";

You forgot a << in there.
You forgot a << in there.


Yeah... Not like that's important or anything.. Oops.

Thanks for the help!
Topic archived. No new replies allowed.