3 Replies - 431 Views - Last Post: 08 March 2010 - 12:45 PM Rate Topic: -----

#1 Likeitbright  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-February 10

something wrong with my project?

Posted 08 March 2010 - 11:01 AM

The program reads the weight in pounds and ounces and outputs the equivalent weight in kilograms and grams. I also included a loop. The problem is I cant call the function. Any help would be appericated.
#include <iostream>
using namespace std;
double grams(double kilo);
double kilo(double pounds, double ounces, double po);
int main()
{
    double pounds, ounces, kilo, grams, weight, po, kilos, gram, kilo2;
    char P, o , p, O, select, ans;
    do
    
    {
    cout <<"Please enter weight in pounds and ounces.n/";
    cin >> pounds, ounces;
    
    
    kilos = kilo(pounds, ounces, po)
    gram = grams(kilo2)
    
    
    cout << "The weight in kilograms"<< kilos <<".n/";
    cout << "The weight in grams"<< gram <<".n/";
    cout << "Try again? Y/N n\";
    cin >> ans;
}
    while (ans == 'Y' || ans == 'y');
    
    double grams(double kilo)
    {
           grams = kilo * 1000
           
           return 1
           }
    double kilo(double pounds, double ounces, double po)
    {
           po = ounces * 16
           kilo = 2.2046(po+pounds)
           kilo = kilo2
           return 1
           }




Is This A Good Question/Topic? 0
  • +

Replies To: something wrong with my project?

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: something wrong with my project?

Posted 08 March 2010 - 11:09 AM

1. Your functions are implemented in main(). They should be implemented outside.
2. Tons of semicolons are missing.
3. ".n/" should be "\n".
4. You have defined variables with the same name as the functions names.
5. No matter of the instructions from your functions, you are returning 1.

Please, learn the syntax, then start coding :)
Was This Post Helpful? 0
  • +
  • -

#3 Likeitbright  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 08-February 10

Re: something wrong with my project?

Posted 08 March 2010 - 11:40 AM

So I fix most the code but I keep getting stuck on the function at the bottom.
#include <iostream>
using namespace std;

int main()
{
    double pounds, ounces, weight, kilos, grams;
    char select, ans;
    
    double kilo(double pounds, double ounces);
    do
   {
    cout <<"Please enter weight in pounds and ounces.\n";
    cin >> pounds, ounces;
    
    
    kilos = kilo(pounds, ounces);
    grams = 1000 * kilos;
    
    
    cout << "The weight in kilograms" << kilos << ".\n";
    cout << "The weight in grams"<< grams <<".\n";
    cout << "Try again? Y/N \n";
    cin >> ans;
}
    while (ans == 'Y' || ans == 'y');
    
{
    double kilo(double pounds, double ounces)
    
           
           kilo = 2.2046((ounces*16)+pounds);
           return kilo
           }


Was This Post Helpful? 0
  • +
  • -

#4 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: something wrong with my project?

Posted 08 March 2010 - 12:45 PM

I have fixed your code, please take a look at comments:
#include <iostream>
using namespace std;

// >>>> add function prototype
double kilo(double, double);

int main()
{
    double pounds, ounces, weight, kilos, grams;
    char select, ans;

    // remove function prototype
    
    do
   {
    cout <<"Please enter weight in pounds and ounces.\n";
    cin >> pounds >> ounces; // >>>> corrected cin
    
    
    kilos = kilo(pounds, ounces);
    grams = 1000 * kilos;
    
    
    cout << "The weight in kilograms" << kilos << ".\n";
    cout << "The weight in grams"<< grams <<".\n";
    cout << "Try again? Y/N \n";
    cin >> ans;
    }while (ans == 'Y' || ans == 'y');
    
} // >>> added bracket
    double kilo(double pounds, double ounces)
	{ // >>> added correct bracket
           double kilo = 2.2046 * ((ounces*16)+pounds);  // >>>  added *
           return kilo; // >>> added semicolon
           }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1