nooby need help with code c++
#1
Posted 21 November 2008 - 09:49 PM
#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
#2
Posted 21 November 2008 - 09:50 PM
Billy3
#3
Posted 22 November 2008 - 11:46 AM
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
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

#4
Posted 22 November 2008 - 03:02 PM
Billy3
#5
Posted 22 November 2008 - 06:36 PM
were am i missing a : there are so many ; im confused
#6
Posted 22 November 2008 - 06:53 PM
Billy3
#7
Posted 22 November 2008 - 06:56 PM
error C2059: syntax error : 'default'
and the same thing but with identifier and system at end
#8
Posted 22 November 2008 - 07:57 PM
i am not known, on Nov 22 2008, 06:56 PM, said:
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
Posted 22 November 2008 - 08:00 PM
error C2061: syntax error : identifier 'system'
thanks
#10
Posted 22 November 2008 - 08:03 PM
Quote
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
Posted 22 November 2008 - 08:25 PM
#12
Posted 23 November 2008 - 12:48 AM
Billy3
#13
Posted 23 November 2008 - 01:39 AM
#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;
}
#14
Posted 23 November 2008 - 09:45 AM
@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
Posted 23 November 2008 - 10:43 AM
groovicus, on Nov 23 2008, 09:45 AM, said:
@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

Help


Back to top











