how would i write code so when someone enters 1 charcter it changes it to somthing else for example if someone entered 100 / 5 it would say 100 ÷ 5.

Recommended Answers

All 6 Replies

never mind with that but what is wrong with this for some reason it gives me errors when compiling
heres code
ps: how would i be able to look up what i saved in data.txt and print it on the screen

#include <stdlib.h>
#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdio.h>
#include <cstdio>
#include <fstream>
using namespace std;


int main()
{

          system("COLOR 5");
          system("TITLE tempature converter");
          
          double firstNumber, answer;
          char f, c, k, operation, repeat, form;
          
          cout <<"\n                  *****************************************";
          cout <<"\n                       Presenting ricky's 2nd program      ";
          cout <<"\n                  *****************************************";
          cout <<"\n                       Version 2.5 released July 7th 2008  ";
          cout <<"\n                  *****************************************";
          cout <<"\n                           A temperature converter         ";
          cout <<"\n                  *****************************************";

          do
          {
          cout <<"\n\n\n\t \t \t \tINSTRUCTIONS \n \n First enter the number you will start with, then the form the number is in \n and lastly the form you want to convert to. this program also saves your what you do to access the file look in the same directory then open data.txt \n \n c = celsius \n k = kalvin \n f = fahrenheit";

          cout <<"\n \n \n \n Enter the number you will start with: ";
          cin >> firstNumber;
          
          cout <<"\n Enter the form of the number you have (c/f/k): ";
          cin >> form;
          
          cout <<"\n Now enter c, f, or k for what you want to convert to: ";  
          cin >> operation;
            
                  if (form == 'f') {
                       if (operation == 'c'){
                          cout <<"\n The answer is: ";
                          answer = ((firstNumber - 32) * 5 / 9);
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                       if (operation == 'k'){           
                          cout <<"\n The answer is: ";
                          answer = ((firstNumber - 32) * 5/9 + 273.15);
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                       if (operation == 'f'){                                 
                          cout <<"\n The answer is: ";
                          answer = firstNumber;
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                  }
                  if (form == 'c') {
                       if (operation == 'c'){
                          cout <<"\n The answer is: ";
                          answer = firstNumber;
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                       if (operation == 'f'){
                          cout <<"\n The answer is: ";
                          answer = (firstNumber * 9 / 5 + 32);
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                       if (operation == 'k'){
                          cout <<"\n The answer is: ";
                          answer = (firstNumber + 273.15);
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                  }
                  if (form == 'k') {
                       if (operation == 'k'){
                          cout <<"\n The answer is: ";
                          answer = firstNumber;
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                       if (operation == 'c'){
                          cout <<"\n The answer is: ";
                          answer = (firstNumber - 273.15);
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                       if (operation == 'f'){
                          cout <<"\n The answer is: ";
                          answer =((firstNumber - 273.15) * 9/5 + 32); //k - f
                          cout << answer;
                          ofstream tempature("data.txt", ios::app);
                          tempature << firstNumber << " " << form << " " << answer << " " << operation << "\n";
                          }
                  
                  else (){  
                  cout <<"\n that wasn't c, f or k";
                  }
          cout <<"\n \n \n \t Do you want to convert another number (y,n): ";
          cin >> repeat;
          if (repeat == 'y'){
             system("CLS");
                }
             }
          }
          while (repeat == 'y');
}

oh also if you see any other errors or suggestions please tell me

hello

oh wow i never would of guessed thanks for all your help guys

oh wow i never would of guessed thanks for all your help guys

Sarcastic, aren't we? If you want help, you need to explain what the program is supposed to do. You have #include statements that are redundant, but that doesn't cause the error. Your problem is here:

else(){

Get rid of the parentheses.

why not use a switch? that would save you a LOT of trouble, be much easier to manage and add and would make your code much more clean ;)

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.