We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,322 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

New at C++, what am i doing wrong, in this simple program

Hey guys, I am very new to c++, and im trying to learn and master the basics

Could you guys please tell me what i am doing wrong here.

I want to maintain my current coding format.

This is a simple converting code. Will be accepting inches, and feet, that will be converted into centimeters.

The problem is that line 13, does not compile

Thanks

#include <iostream> 
#include <cmath>
#include <string>

using namespace std;

int main()
{
    const double feet_to_inch = 12; // conversion from feet to inches
    const double inch_to_centi = 2.54; // conversion from inches to centimenters
    
    int feet ; 0
    double inches ; = 0.0, total_inches = 0.0 ;
    double centimeters ; 0.0
    
    // Conversion Program to centimeters
    cout << "The quieter you become, the more you will be able to hear"; 
    
    // Entered value by user in feet
    cout << "\n Enter in feet" ;
    cin >> feet ;
    
    // Entered value by user in inches
    cout << "\n Enter in inches" ;
    cin >>  inches ;
   
    //Calculate number of inches
    total_inches = inches + feet * feet_to_inch ;
    
    // Convert to centimeters
    centimeters = total_inches * inch_to_centi ;

    // Output results
    cout << "/n The Result is :" << centimeters;
    
    char c; 
    cout << "/n Press anything to Exit" ;
    cin >> c;
    
    return 0;
    
}
3
Contributors
5
Replies
37 Minutes
Discussion Span
1 Year Ago
Last Updated
6
Views
seanster138
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

You miss a closing quotation mark on line 17, other than that seems fine to me.

jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0

You miss a closing quotation mark on line 17, other than that seems fine to me.

when i try to compile, i get an error at line 13

seanster138
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Why just you do not use simple format:

double inches = 0.0;
double total_inches = 0.0;

BTW more on double usage is for example here
http://www.cplusplus.com/forum/articles/3827/

Peter4n31
Newbie Poster
21 posts since Sep 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Why just you do not use simple format:

double inches = 0.0;
double total_inches = 0.0;

BTW more on double usage is for example here
http://www.cplusplus.com/forum/articles/3827/

when i use that format, im still getting the error at line 13

seanster138
Newbie Poster
3 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

That's because of what you did in line 12.
Why?

int feet ; 0

Should be

int feet=0;

In general, all your variable declarations are wrong. While constants are correct.
After fixing all the variable declarations compiled properly using g++ -Wall The final code is like this:

#include <iostream>
#include <cmath>
#include <string>
 
using namespace std;
 
int main()
{
	const double feet_to_inch = 12; // conversion from feet to inches
	const double inch_to_centi = 2.54; // conversion from inches to centimenters
	 
	int feet= 0;
	double inches = 0.0;
	double total_inches = 0.0 ;
	double centimeters = 0.0;
	 
	// Conversion Program to centimeters
	cout << "The quieter you become, the more you will be able to hear";
	 
	// Entered value by user in feet
	cout << "\n Enter in feet" ;
	cin >> feet ;
	 
	// Entered value by user in inches
	cout << "\n Enter in inches" ;
	cin >> inches ;
	 
	//Calculate number of inches
	total_inches = inches + feet * feet_to_inch ;
	 
	// Convert to centimeters
	centimeters = total_inches * inch_to_centi ;
	 
	// Output results
	cout << "/n The Result is :" << centimeters;
	 
	char c;
	cout << "/n Press anything to Exit" ;
	cin >> c;
	 
	return 0;
 
}
jaskij
Junior Poster
106 posts since Oct 2011
Reputation Points: 55
Solved Threads: 19
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0763 seconds using 2.75MB