Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

nooby need help with code c++


  • Please log in to reply
19 replies to this topic

#1 i am not known

i am not known

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:04:22 AM

Posted 21 November 2008 - 09:49 PM

whats wrong with my code

#include "stdafx.h"
#include <iostream>
using namespace std;


int main(void)
{
system("TITLE Calculator"); //this makes the title change when i programme
system("COLOR 2"); // makes it look different green writing black background

char cChar; //character as in + / a b
double dfirstnumber;
double dsecondnumber;
char cDoagain


;do
{
system("CLS");

std::cout << "please enter the first number you would like to use " << endl;

cin >> dfirstnumber;

std::cout << "please enter the operation you would like to use (+, -, / and * )" << endl;

cin >> cChar;

std::cout << "please enter the second number you would like to use " << endl;

cin >> dsecondnumber

;switch (cChar)//anilises which code is the most apropriet so if you pick the + statment is will go through the plus set of code aka a different kind of if
{
case '+';
std::cout << "The anwser is! " << dfirstnumber << ' + ' << dsecondnumber << '=' << (dfirstnumber + dsecondnumber)<<endl;
break;
case '-';
std::cout << "The anwser is! " << dfirstnumber << ' - ' << dsecondnumber << '=' << (dfirstnumber - dsecondnumber)<<endl;
break;
case '*';
std::cout << "The anwser is! " << dfirstnumber << ' * ' << dsecondnumber << '=' << (dfirstnumber * dsecondnumber)<<endl;
break;
case '/';
if (dsecondnumber == 0) (
std::cout << "invaled operation " << endl;
)else(

std::cout << "The anwser is! " << dfirstnumber << ' / ' << dsecondnumber << '=' << (dfirstnumber / dsecondnumber)<<endl;
break;


}
break;
default:
std::cout << "invaled operation" << endl;
break;










;system("pause");
return 0;
}







it found the problems
1>------ Build started: Project: me trying part 2, Configuration: Debug Win32 ------
1>Compiling...
1>me trying part 2.cpp
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(35) : error C2143: syntax error : missing ':' before ';'
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(38) : error C2143: syntax error : missing ':' before ';'
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(41) : error C2143: syntax error : missing ':' before ';'
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(44) : error C2143: syntax error : missing ':' before ';'
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(46) : error C2143: syntax error : missing ')' before ';'
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(47) : error C2059: syntax error : ')'
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(49) : error C2143: syntax error : missing ')' before ';'
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(55) : error C2047: illegal default
1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(72) : fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(7)' was matched
1>Build log was saved at "file://c:\Documents and Settings\Joseph\My Documents\Visual Studio 2008\Projects\me trying part 2\me trying part 2\Debug\BuildLog.htm"
1>me trying part 2 - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


nooby needs help please its driving me insane
I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man

BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:22 AM

Posted 21 November 2008 - 09:50 PM

Exactly what the compiler's telling you. You're missing ;s in your code.
Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 jpshortstuff

jpshortstuff

    WhatTheTech Teacher


  • Members
  • 660 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:UK
  • Local time:10:22 AM

Posted 22 November 2008 - 11:46 AM

You also have what appears to be the start of a do-while loop, but there is no end brace, and no while/condition.

In one case, you also appear to have too many ;s:
;system("pause");

Edited by jpshortstuff, 22 November 2008 - 11:46 AM.

Trained at the What The Tech Classroom where you too could learn to help others.

My help is free, however, if you wish to make a small donation to show appreciation and to help me continue the fight against Malware, then click here Posted Image

Posted Image

#4 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:22 AM

Posted 22 November 2008 - 03:02 PM

It's usually a good idea to put the ;s at the end of your statements rather than at the beginning of the next statement.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#5 i am not known

i am not known
  • Topic Starter

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:04:22 AM

Posted 22 November 2008 - 06:36 PM

ye but my main problem it the 1>c:\documents and settings\joseph\my documents\visual studio 2008\projects\me trying part 2\me trying part 2\me trying part 2.cpp(35) : error C2143: syntax error : missing ':' before ';'

were am i missing a : there are so many ; im confused
I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man

#6 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:22 AM

Posted 22 November 2008 - 06:53 PM

What is the content of lines 34, 35, and 36?

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#7 i am not known

i am not known
  • Topic Starter

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:04:22 AM

Posted 22 November 2008 - 06:56 PM

ok i fixed my old problems all but

error C2059: syntax error : 'default'

and the same thing but with identifier and system at end
I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man

#8 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:22 AM

Posted 22 November 2008 - 07:57 PM

ok i fixed my old problems all but

error C2059: syntax error : 'default'

and the same thing but with identifier and system at end

I suspect a problem with the number if {}s. Ensure that your default: statement is contained within the block defined for the switch.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#9 i am not known

i am not known
  • Topic Starter

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:04:22 AM

Posted 22 November 2008 - 08:00 PM

hey it worked now all i need to do is fix
error C2061: syntax error : identifier 'system'

thanks
I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man

#10 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:22 AM

Posted 22 November 2008 - 08:03 PM

;system("pause");

Put the ; on the line it ends where it belongs, and see if the compiler no longer chokes.

You also may need to include cstdlib:
#include <cstdlib>
or alternately
#include <stdlib.h>

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#11 i am not known

i am not known
  • Topic Starter

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:04:22 AM

Posted 22 November 2008 - 08:25 PM

no still not working i have used system("pause") before i don't know whats wrong
I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man

#12 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:22 AM

Posted 23 November 2008 - 12:48 AM

Well noone here can help unless you post the code :thumbsup:

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#13 i am not known

i am not known
  • Topic Starter

  • Members
  • 113 posts
  • OFFLINE
  •  
  • Local time:04:22 AM

Posted 23 November 2008 - 01:39 AM

:thumbsup: sorry

#include "stdafx.h"
#include <iostream>
using namespace std;


int main(void)
{
	system("TITLE Calculator"); //this makes the title change when i programme
	system("COLOR 2"); // makes it look different green writing black background
	
	char cChar; //character as in + / a b
	double dfirstnumber;
	double dsecondnumber;
	char cDoagain


;do
{	
	system("CLS");
	
	std::cout << "please enter the first number you would like to use " << endl;
	
	cin >> dfirstnumber;
	
	std::cout << "please enter the operation you would like to use (+, -, / and * )" << endl;
	
	cin >> cChar;

	std::cout << "please enter the second number you would like to use " << endl;

	cin >> dsecondnumber

;switch (cChar)//anilises which code is the most apropriet so if you pick the + statment is will go through the plus set of code aka a different kind of if
	{
		  case '+':;
		  std::cout << "The anwser is! " << dfirstnumber << ' + ' << dsecondnumber << '=' << (dfirstnumber + dsecondnumber)<< endl;
		  break;
		  case '-':;
		  std::cout << "The anwser is! " << dfirstnumber << ' - ' << dsecondnumber << '=' << (dfirstnumber - dsecondnumber)<< endl;
		  break;
		  case '*':;
		  std::cout << "The anwser is! " << dfirstnumber << ' * ' << dsecondnumber << '=' << (dfirstnumber * dsecondnumber)<< endl;
		  break;
		  case '/':;
			  if (dsecondnumber == 0) (
				  std::cout << "invaled operation " << endl);
			  else(

		  std::cout << "The anwser is! " << dfirstnumber << ' / ' << dsecondnumber << '=' << (dfirstnumber / dsecondnumber)<< endl);
		  break;

	default: 
	std::cout << "invaled operation" << endl;
	break;
	}	
		





		
}


system("pause");
return 0;

}

I hear a boy only has a certain amount of tears one day the pain and dissapointment happen so often the pain dissapers and the boy becomes a man

#14 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:03:22 AM

Posted 23 November 2008 - 09:45 AM

I am not following your logic. Billy suggested some changes, which you obviously didn't do. And you think it will work without making the changes because....?

@Billy: The compiler ignores white space, so the fact that the semi-colon is not where it is supposed to be doesn't matter. Of course, to humans trying to help someone debug their problems, it is a huge irritation. I won't even look at improperly formatted code anymore.

#15 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:02:22 AM

Posted 23 November 2008 - 10:43 AM

I am not following your logic. Billy suggested some changes, which you obviously didn't do. And you think it will work without making the changes because....?

@Billy: The compiler ignores white space, so the fact that the semi-colon is not where it is supposed to be doesn't matter. Of course, to humans trying to help someone debug their problems, it is a huge irritation. I won't even look at improperly formatted code anymore.

That's true.. just thinking it may have ticked off a bug in the compiler ;)

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users