6 Replies - 467 Views - Last Post: 23 December 2009 - 06:24 PM Rate Topic: -----

#1 zzzstarzzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-December 09

Basic errors with my code

Posted 23 December 2009 - 09:12 AM

Hi,

I am learning C++ , and sometimes just could not find where the errors are;
Could you please point me out while I could not compile this code;

#include<iostream>
using namespace std;
void main ()

{
		  
	 int cvtype =0;
	 float temp = 0;
	 cout << "Select Coversition Type (1) - C to F ,(2) F to C==> ";
	 cin >> "cvtype";
	 cout << "Input Temperature ==> ";
	 cin >> temp;
	 
	 if (cvtype == 1)
	 {
	 cout << "32 + (temp +1.8)";
	 cout << "degrees F";
	 }
	 else
	 {
	 cout << "(temp - 32)/1.8";
	 cout << "degree C";
	 
	 }
	 
}


Thanks so much

Is This A Good Question/Topic? 0
  • +

Replies To: Basic errors with my code

#2 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,219
  • Joined: 23-August 08

Re: Basic errors with my code

Posted 23 December 2009 - 09:28 AM

When you have errors, it is right and proper to copy and paste the ACTUAL errors in the code into your post, so the WE don't have to be mind readers.

For starters, main returns int in C++ ALWAYS, not void.
Second, you don't seem to understand the use of variables. Here
cin >> "cvtype";

what is "cvtype"? Do you think it's the same thing as cvtype?

Same kind of situation here
cout << "(temp - 32)/1.8";


Go back to your book and/or lecture notes and review the use of variables.
Was This Post Helpful? 0
  • +
  • -

#3 gautam353  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 15-December 09

Re: Basic errors with my code

Posted 23 December 2009 - 09:37 AM

As jack say's go and check your fundamentals.

should'nt "32 + (temp +1.8)"; be written without the quotes

rewrite your code and avoid such careless mistakes....

This post has been edited by gautam353: 23 December 2009 - 09:41 AM

Was This Post Helpful? 0
  • +
  • -

#4 Huzi94  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 119
  • Joined: 14-November 09

Re: Basic errors with my code

Posted 23 December 2009 - 11:07 AM

Maybe you should this.

#include<iostream>
using namespace std;
int main ()

{
		  
	 int cvtype =0;
	 float temp = 0;
	 cout << "Select Coversition Type (1) - C to F ,(2) F to C==> ";
	 cin >> cvtype;
	 cout << "Input Temperature ==> ";
	 cin >> temp;
	 
	 if (cvtype == 1)
	 {
	 cout << 32 + (temp +1.8);
	 cout << "degrees F";
	 }
	 else
	 {
	 cout << (temp - 32)/1.8;
	 cout << "degree C";
	 
	 }
	 
}

Was This Post Helpful? 0
  • +
  • -

#5 apw5020  Icon User is offline

  • D.I.C Addict

Reputation: 78
  • View blog
  • Posts: 666
  • Joined: 26-March 09

Re: Basic errors with my code

Posted 23 December 2009 - 12:01 PM

View PostHuzi94, on 23 Dec, 2009 - 02:07 PM, said:

Maybe you should this.

#include<iostream>
using namespace std;
int main ()

{
		  
	 int cvtype =0;
	 float temp = 0;
	 cout << "Select Coversition Type (1) - C to F ,(2) F to C==> ";
	 cin >> cvtype;
	 cout << "Input Temperature ==> ";
	 cin >> temp;
	 
	 if (cvtype == 1)
	 {
	 cout << 32 + (temp +1.8);
	 cout << "degrees F";
	 }
	 else
	 {
	 cout << (temp - 32)/1.8;
	 cout << "degree C";
	 
	 }
	 
}


Maybe you should return 0;.

And let him learn something by allowing him to figure it out on his own.
Was This Post Helpful? 0
  • +
  • -

#6 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,449
  • Joined: 09-June 09

Re: Basic errors with my code

Posted 23 December 2009 - 12:37 PM

@Huzi94
you just killed his learning process -- gold star
Was This Post Helpful? 0
  • +
  • -

#7 zzzstarzzz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-December 09

Re: Basic errors with my code

Posted 23 December 2009 - 06:24 PM

Thanks for all comments.
As JackOfAllTrades said, I need to work more on my basic.
I am very new here, and really sorry for posting without stating the error.

I will work more on this :) Again, thanks so much!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1