BleepingComputer.com: nooby need help with code c++

Jump to content

  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

nooby need help with code c++

#1 User is offline   i am not known 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 113
  • Joined: 17-August 08

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

#2 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 21 November 2008 - 09:50 PM


#3 User is offline   jpshortstuff 

  • WhatTheTech Teacher
  • PipPipPipPipPip
  • Find Topics
  • Group: Malware Response Team
  • Posts: 660
  • Joined: 15-June 07
  • Gender:Male
  • Location:UK

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");

This post has been 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 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

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

#5 User is offline   i am not known 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 113
  • Joined: 17-August 08

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 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 22 November 2008 - 06:53 PM


#7 User is offline   i am not known 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 113
  • Joined: 17-August 08

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 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 22 November 2008 - 07:57 PM

View Posti am not known, on Nov 22 2008, 06:56 PM, said:

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

#9 User is offline   i am not known 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 113
  • Joined: 17-August 08

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 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 22 November 2008 - 08:03 PM

Quote

;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

#11 User is offline   i am not known 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 113
  • Joined: 17-August 08

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 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 23 November 2008 - 12:48 AM


#13 User is offline   i am not known 

  • Member
  • PipPip
  • Find Topics
  • Group: Members
  • Posts: 113
  • Joined: 17-August 08

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

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.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#15 User is offline   Billy O'Neal 

  • Bleepin Engineer GRADUATE
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Malware Response Instructor
  • Posts: 10,403
  • Joined: 17-January 08
  • Gender:Male
  • Location:Cleveland, Ohio

Posted 23 November 2008 - 10:43 AM

View Postgroovicus, on Nov 23 2008, 09:45 AM, said:

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

Share this topic:


  • 2 Pages +
  • 1
  • 2
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users