I need help making a program that include meter yards and feet. my c+ class is only in chapter 4 of the c++ book.
function header should be

void convertMeters(int meters)

int main
1. ask for the number of meters
2. read in the number of meters
3. call your function
4. the output should look like:

??? meters is:
??? inches
??? feet
??? yards
??? miles

my class program looks like this

Attachments
/********************
*     program name:       Skeleton
*     author:             Jimmy
*     date due:
*     remarks:            the basic parts of a C Program
**********************************************/

/********************************************
*    constants
********************************************/
#define PI 3.14159   // hold value and never changes

/**************************************
*     libraries
***************************************/
#include <iostream>                       // needed for cin/count
#include <cmath>                         // needed for math functions
using namespace std;

/****************************
*    prototypes    //declared function so main can find
*****************************/
void exFunc01();     //prototype to function
void exFunc02();
void pass2Func(double z);
void pass22Func(double x, int v);
double returnFunc(double x, int v);

int main ()  // prototype to main
{
    double printAns;
    int a;
    a = 3;
    double x = sqrt(5.8);
    cout << x << "\n";
    
    cout << "hi mom  \n";
    exFunc01();
    exFunc02();
    pass2Func(x);
    pass22Func(x, a);
    printAns = returnFunc(x,a);
    cout << "number returned is" <<printAns;
    system("pause");
}   
double returnFunc(double x, int v)
{   
    double ans;
    cout << " number passed is " << x << "\n";
    cout << " int passed is " << v << "\n";
    ans = x * v;
    return ans;
} 
void pass2Func(double x) // local to functin
{
    cout << " number passed is " << x << "\n";
}
void pass22Func(double x, int v)
{   
    cout << " number passed is " << x << "\n";
    cout << " int passed is " << v << "\n";
}
void exFunc01()
{
    cout << " in function01 \n";
}
void exFunc02()
{
    cout << " in function02 \n";
}

What exactly is the problem with your program? What parts do you not understand or are having trouble with?

im thinking the protype will be void convertMeters(int meters) then int main where i am stuck on

since i am looking for 5 problem. Wouldn't i have to name my int after main be int s,r,x,y,z ; if i was tring to print out
??? meters is:
??? inches
??? feet
??? yards
??? miles

One method of attack for this problem would be to create separate functions for each conversion. You could have a function like this: void printMetersAsFeet(int meters); It would perform the conversion and display the results. You could then adapt this function to perform the other conversions required of you.

so far I think I have this

**************************************
*     libraries
***************************************/
#include <iostream>                       // needed for cin/count
#include <cmath>                         // needed for math functions
using namespace std;

/****************************
*    prototypes    //declared function so main can find
*****************************/
void convertMeters(int meters)


int main()
}
int s,r,x,y,z;

wouldn't i have to define the var. next?

I don't know what you're planning on using those variables at the bottom of your program, but most likely you won't need them.

What you need to do next is to create the body of convertMeters(). You'll want a few statements that print out what the specified number of meters is in a few different formats. For example: printf("%d meters is %f feet.\n", meters, meters*3.2808);

thanks for helping I figure it out I made it look like this

void convertMeters(int meters);


int main()
{
  int meters;
  cout << "Amount: ";
  cin >> meters;
  convertMeters(meters);
  
      system("pause");
}
void convertMeters(int meters)
{
  double inches = meters / .254;
  double feet = meters / .3048;
  double yards = meters / .9144;
  double miles = meters / 1609.344;
  


  //std::cout.setf(std::ios_base::fixed, std::ios_base::floatfield);
  //std::cout.precision(3);

  std::cout << meters << " meters is: \n   "
    << inches << " inches \n  "
    << feet    << " feet \n  " 
    << yards  << " yards  \n  "
    << miles  << " miles \n  ";
}
This article has been dead for over six months. Start a new discussion instead.