this program works but i need to put in a loop that the user 10 times to input a value and you load it ino an array

#include<iostream.h>
#include<conio.h>
//Author:
//Object:
//Date:

void ctof(void); //function declarations (prototypes)
void ftoc(void);

float c,f; // (outside the functions)

main()
{
int option;
//--------------output the menu to the screen -----
do{
clrscr();
cout<<" 2012 Convertor"<<endl<<endl;
cout<<" Main Menu"<<endl<<endl;
cout<<"1) f -> c "<<endl;
cout<<"2) c -> f "<<endl<<endl;
cout<<"3) Exit the Program"<<endl<<endl;
cout<<"Please enter your choice: ";

cin>>option;

//-----------------what was the operators choice--
if (option == 1)
ctof(); //call the ctof function

//-------- they want to convert from F -> C ---
if (option == 2)
ftoc(); //call the ftoc function

}while(option !=3); //exit loop if option = 3

getch();
} //end of the program
//------------
void ftoc(void)
{

clrscr();

cout<<"Please enter your 1st Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 2nd Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;

cout<<"Please enter your 3rd Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 4th Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 5th Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 6th Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;;
cout<<endl; //To end the line

cout<<"Please enter your 7th Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 8th Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 9th Reading:";
cin>>f;
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 10th Reading:";
cin>>f;
//readings now all entered into the string
c=(f-32)/9*5; //do calculation
cout<<f<<" degress fahrenheit = "<<c<<" degrees celcius"<<endl;
cout<<"Please press any key to continue..";
getch();
}

//--------------------------------------------------------------------------
void ctof(void)
{

clrscr();

cout<<"Please enter your 1st Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 2nd Reading:";
cin>>c;
cout<<endl; //To end the line

cout<<"Please enter your 3rd Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 4th Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 5th Reading:";
cin>>c;
c=f/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 6th Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 7th Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;


cout<<"Please enter your 8th Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 9th Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line

cout<<"Please enter your 10th Reading:";
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<"Please press any key to continue..";
getch(); // calculation now done data done
}

Recommended Answers

All 18 Replies

Replace that function with following:

void ctof(void)
{

clrscr();

/*Basicly i starts at 1 ; while i is less than 10; increment 1 by 1 at the end of the line and start over with i now value at 2 so on..*/
for (int i = 1; i != 10; i ++){
 cout<<"Please Enter Reading #" << i << endl;
 cin>>c;
 f=c/5*9+32; //do calculation
 cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
 cout<<endl; //To end the line
}

But you have no arrays stored so you'd change.
c
to
c

keep as i so it starts at:

c[1] (aka c when at first pass through loop)
c[2] (aka c when at second pass through loop, since i increments at end of loop)
c[3] (aka c when at third pass through loop, itll keep going untill 10.

thanks also were do i put the 1D array were it stores the 10 temperature reading
#include<iostream.h>
#include<conio.h>
//Author:
//Object:
//Date:

void ctof(void); //function declarations (prototypes)
void ftoc(void);

float c,f; // (outside all functions)

main()
{
int option;
//---------------------------output the menu to the screen -------------------
do{
clrscr();
cout<<" 2012 Convertor"<<endl<<endl;
cout<<" Main Menu"<<endl<<endl;
cout<<"1) f -> c "<<endl;
cout<<"2) c -> f "<<endl<<endl;
cout<<"3) Exit the Program"<<endl<<endl;
cout<<"Please enter your choice: ";

cin>>option;

//-----------------------------what was the users choice?---------------------
if (option == 1)
ctof(); //call the ctof function

//---------------------- they want to convert F -> C ----------------------
if (option == 2)
ftoc(); //call the ftoc function

}while(option !=3); //exit loop if option = 3

getch();
} //end of the program
//--------------------------------------------------------------------------
void ftoc(void)
{


clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>f;
c=f/5*9+32; //do calculation
cout<<f<<" degress celcius = "<<c<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
}

//--------------------------------------------------------------------------
void ctof(void)
{

clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
getch();
}

Define f and c like this:

float f[11], c[11];

And in for loop change c to c and f to f.

i change it but the program when convert says it like 0*004354a0 so what did i do wrong
clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
getch();
}

You missed one.

cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;

This is how it should look like.

cout<<c[i]<<" degress celcius = "<<f[i]<<" degrees fahrenheit"<<endl;
commented: very helpfull +1

first if i did not say it already thank you so much for help so far.ok i am meant to have a function called controller() ask user fore scale in which data will be entered gets the 10 temperatures into 1D array i think that is done but were should i put the controller() at #include<iostream.h>
#include<conio.h>
//Author:
//Object:
//Date:

void ctof(void); //function declarations (prototypes)
void ftoc(void);

float f[11], c[11]; // (outside all functions)

main()
{
int option;
//---------------------------output the menu to the screen -------------------
do{
clrscr();
cout<<" 2012 Convertor"<<endl<<endl;
cout<<" Main Menu"<<endl<<endl;
cout<<"1) f -> c "<<endl;
cout<<"2) c -> f "<<endl<<endl;
cout<<"3) Exit the Program"<<endl<<endl;
cout<<"Please enter your choice: ";

cin>>option;

//-----------------------------what was the users choice?---------------------
if (option == 1)
ctof(); //call the ctof function

//---------------------- they want to convert F -> C ----------------------
if (option == 2)
ftoc(); //call the ftoc function

}while(option !=3); //exit loop if option = 3

getch();
} //end of the program
//--------------------------------------------------------------------------
void ftoc(void)
{


clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>f;
c=f/5*9+32; //do calculation
cout<<f<<" degress celcius = "<<c<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
}

//--------------------------------------------------------------------------
void ctof(void)
{

clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
getch();
}

Heres a Fully Working Version Of your Code:

Compiled In with G++ on linux.

>> you had a few errors but its a working version here now

#include <iostream>
#include <cstdio>
using namespace std;
void ctof(void); //function declarations (prototypes)
void ftoc(void);
float c[10],f[10]; // (outside all functions)
int main(){
int option;
do{
  cout<<" 2012 Convertor"<<endl<<endl;
  cout<<" Main Menu"<<endl<<endl;
  cout<<"1) f -> c "<<endl;
  cout<<"2) c -> f "<<endl<<endl;
  cout<<"3) Exit the Program"<<endl<<endl;
  cout<<"Please enter your choice: ";
  cin>>option;
  if (option == 1)
  ctof(); //call the ctof function
  if (option == 2)
  ftoc(); //call the ftoc function
}while(option !=3); //exit loop if option = 3

/*This Is All Your Readings Stored*/
//This Will Load When You Exit Program (option 3)
//getchar(); only needed here in main no where else!
for(int i=0;i<10;i++){
 cout << "Readings :# "<< i << "Degree C: " << c[i] << "Degree F: "<< f[i] << endl;
}
getchar();
}
void ftoc(void){
for (int i = 1; i != 11; i ++){
 cout<<"Please Enter Reading #" << i << endl;
 cin>>f[i];
 c[i]=f[i]/5*9+32; //do calculation
 cout<<f[i]<<" degress celcius = "<<c[i]<<" degrees fahrenheit"<<endl;
 cout<<endl; //To end the line
 }
}
void ctof(void){
for (int i = 1; i != 11; i ++){
 cout<<"Please Enter Reading #" << i << endl;
 cin>>c[i];
 f[i]=c[i]/5*9+32; //do calculation
 cout<<c[i]<<" degress celcius = "<<f[i]<<" degrees fahrenheit"<<endl;
 cout<<endl; //To end the line
 }
}
commented: very helpfull +1

first if i did not say it already thank you so much for help so far.ok i am meant to have a function called controller() ask user fore scale in which data will be entered gets the 10 temperatures into 1D array i think that is done but were should i put the controller() at

Can you explain what is controller() function supposed to do? I don't really get it :)
Are you supposed to enter values for temperatures in controller instead of ctof and ftoc or?

Controller ask user fore scale in which data will be entered gets the 10 temperatures into 1D array . calls either the ctof() or ftoc() fuction passing a temperature to be converted.prints out the result sent back from the function in a suitable format

#include<iostream.h>
#include<conio.h>
//Author:
//Object:
//Date:

void ctof(void); //function declarations (prototypes)
void ftoc(void);

float f[11], c[11]; // (outside all functions)

main()
{
int option;
//---------------------------output the menu to the screen -------------------
do{
clrscr();
cout<<" 2012 Convertor"<<endl<<endl;
cout<<" Main Menu"<<endl<<endl;
cout<<"1) f -> c "<<endl;
cout<<"2) c -> f "<<endl<<endl;
cout<<"3) Exit the Program"<<endl<<endl;
cout<<"Please enter your choice: ";

cin>>option;

//-----------------------------what was the users choice?---------------------
if (option == 1)
ctof(); //call the ctof function

//---------------------- they want to convert F -> C ----------------------
if (option == 2)
ftoc(); //call the ftoc function

}while(option !=3); //exit loop if option = 3

getch();
} //end of the program
//--------------------------------------------------------------------------
void ftoc(void)
{


clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>f;
c=f/5*9+32; //do calculation
cout<<f<<" degress celcius = "<<c<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
}

//--------------------------------------------------------------------------
void ctof(void)
{

clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
getch();
}

Something like this?

#include <iostream>
#include <cstdio>
using namespace std;

void ctof(void); //function declarations (prototypes)
void ftoc(void);
void controller(int a);
float c[10],f[10]; // (outside all functions)

int main()
{
    int option;
    do{
      cout<<" 2012 Convertor"<<endl<<endl;
      cout<<" Main Menu"<<endl<<endl;
      cout<<"1) f -> c "<<endl;
      cout<<"2) c -> f "<<endl<<endl;
      cout<<"3) Exit the Program"<<endl<<endl;
      cout<<"Please enter your choice: ";
      cin>>option;
      if (option == 1)
      {
          controller(1);
          ctof();
      }
      if (option == 2)
      {
          controller(2);
          ftoc();
      }
    }while(option !=3); //exit loop if option = 3

    /*This Is All Your Readings Stored*/
    //This Will Load When You Exit Program (option 3)
    //getchar(); only needed here in main no where else!
    for(int i=0;i<10;i++){
        cout << "Readings :# "<< i << "Degree C: " << c[i] << "Degree F: "<< f[i] << endl;
    }
    getchar();
}
void controller (int a)
{
    for (int i = 1; i != 11; i ++)
    {
        if(a == 1)
        {
            cout<<"Please Enter Reading # " << i << ": ";
            cin>>c[i];
        }
        else if(a == 2)
        {
            cout<<"Please Enter Reading # " << i << ": ";
            cin>>f[i];
        }
    }
}
void ftoc(void)
{
    for (int i = 1; i != 11; i ++)
    {
         c[i]=f[i]/5*9+32; //do calculation
         cout<<f[i]<<" degress celcius = "<<c[i]<<" degrees fahrenheit"<<endl;
    }
}
void ctof(void)
{
    for (int i = 1; i != 11; i ++)
    {
         f[i]=c[i]/5*9+32; //do calculation
         cout<<c[i]<<" degress celcius = "<<f[i]<<" degrees fahrenheit"<<endl;
    }
}

help <cstdio> i cannot use that as it says unable to open it also say call to undefined fuction getch();

help <cstdio> i cannot use that as it says unable to open it also say call to undefined fuction getch();

Which compiler are you using?

Replace cstdio with #include<conio.h>

borland 5.02 so willl not let me use cstdio

so i need this borland 5.02 so willl not let me use cstdio. Controller ask user fore scale in which data will be entered gets the 10 temperatures into 1D array . calls either the ctof() or ftoc() fuction passing a temperature to be converted.prints out the result sent back from the function in a suitable format.

#include<iostream.h>
#include<conio.h>
//Author:
//Object:
//Date:

void ctof(void); //function declarations (prototypes)
void ftoc(void);

float f[11], c[11]; // (outside all functions)

main()
{
int option;
//---------------------------output the menu to the screen -------------------
do{
clrscr();
cout<<" 2012 Convertor"<<endl<<endl;
cout<<" Main Menu"<<endl<<endl;
cout<<"1) f -> c "<<endl;
cout<<"2) c -> f "<<endl<<endl;
cout<<"3) Exit the Program"<<endl<<endl;
cout<<"Please enter your choice: ";

cin>>option;

//-----------------------------what was the users choice?---------------------
if (option == 1)
ctof(); //call the ctof function

//---------------------- they want to convert F -> C ----------------------
if (option == 2)
ftoc(); //call the ftoc function

}while(option !=3); //exit loop if option = 3

getch();
} //end of the program
//--------------------------------------------------------------------------
void ftoc(void)
{


clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>f;
c=f/5*9+32; //do calculation
cout<<f<<" degress celcius = "<<c<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
}

//--------------------------------------------------------------------------
void ctof(void)
{

clrscr();


for (int i = 1; i != 11; i ++){
cout<<"Please Enter Reading #" << i << endl;
cin>>c;
f=c/5*9+32; //do calculation
cout<<c<<" degress celcius = "<<f<<" degrees fahrenheit"<<endl;
cout<<endl; //To end the line
}
getch();
}

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

using namespace std;

void ctof(void); //function declarations (prototypes)
void ftoc(void);
void controller(int a);
float c[11],f[11]; // (outside all functions)

int main()
{
    int option;
    do{
      cout<<" 2012 Convertor"<<endl<<endl;
      cout<<" Main Menu"<<endl<<endl;
      cout<<"1) f -> c "<<endl;
      cout<<"2) c -> f "<<endl<<endl;
      cout<<"3) Exit the Program"<<endl<<endl;
      cout<<"Please enter your choice: ";
      cin>>option;
      if (option == 1)
      {
          controller(1);
          ctof();
      }
      if (option == 2)
      {
          controller(2);
          ftoc();
      }
    }while(option !=3); //exit loop if option = 3

    /*This Is All Your Readings Stored*/
    //This Will Load When You Exit Program (option 3)
    //getchar(); only needed here in main no where else!
    for(int i=0;i<10;i++){
        cout << "Readings :# "<< i << "Degree C: " << c[i] << "Degree F: "<< f[i] << endl;
    }
    getch();
}
void controller (int a)
{
    for (int i = 1; i != 11; i ++)
    {
        if(a == 1)
        {
            cout<<"Please Enter Reading # " << i << ": ";
            cin>>c[i];
        }
        else if(a == 2)
        {
            cout<<"Please Enter Reading # " << i << ": ";
            cin>>f[i];
        }
    }
}
void ftoc(void)
{
    for (int i = 1; i != 11; i ++)
    {
         c[i]=f[i]/5*9+32; //do calculation
         cout<<f[i]<<" degress celcius = "<<c[i]<<" degrees fahrenheit"<<endl;
    }
}
void ctof(void)
{
    for (int i = 1; i != 11; i ++)
    {
         f[i]=c[i]/5*9+32; //do calculation
         cout<<c[i]<<" degress celcius = "<<f[i]<<" degrees fahrenheit"<<endl;
    }
}

hi i am getting one error saying namespace name expected this line using namespace std;

Ah.. Remove using namespace std; from 4th line.
I'm using CodeBlocks so I don't know which parts are not working in Borland..

thanks so much

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.