A Curious Thing...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Apr 2009
Posts: 4
Reputation: archiphile is an unknown quantity at this point 
Solved Threads: 0
archiphile archiphile is offline Offline
Newbie Poster

A Curious Thing...

 
0
  #1
Apr 15th, 2009
I am not only new here, but, I am a complete newbie to programing. I was on the hunt for some beginner tutorials today on the web. I found what I thought would be a simple yet in depth problem. I spent the last hour making sure that I had typed everything exactly as instructed (you tube video) and when I tried to compile, MSVC++EXS came back with about twenty errors. Now I saw the code run on the video, so I feel confident that it should work. But no dice here. I will post both a link to the original and the code as follows:

Video link(s) http://www.youtube.com/watch?v=FPKmF...eature=related

my code;
// This is a program about loops, switch statements, ifelse statements
//and applying them to another faily simple programme.

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

{
	system ("TITLE Calculator");
	system ("COLOR 2");
	char cChar;
	double dfirstnumber;
	double dsecondnumber;
	char cDoagain;

do
{
	system ("CLS");
	cout<< "Please enter the first number that you would like to use." << endl;
	cin>> dfistnubmer;
	cout<< "Please enter the operation that you would like to complete."
    <<" (+,-,* and /)"<< endl;
	cin>> cChar;
	cin<< ("Please enter the second number that you would like to use.") << endl;

    switch (cChar);
    { 
    case "+";
         cout<< " The Answer is:"<< dfirstnumber << "+" << dsecondnumber 
         << dfirstnumber << "=" << dfirstnumber + dsecondnumber 
         << endl;

    case "-";
         cout<< " The Answer is:"<< dfirstnumber << "-" << dsecondnumber 
         << dfirstnumber << "=" << dfirstnumber - dsecondnumber 
         << endl;
         break;
    case "*";
         cout<< " The Answer is:"<< dfirstnumber << "*" << dsecondnumber 
         << dfirstnumber << "=" << dfirstnumber * dsecondnumber 
         << endl;
         break;  
    case "x";
         cout<< " The Answer is:"<< dfirstnumber << "x" << dsecondnumber 
         << dfirstnumber << "=" << dfirstnumber * dsecondnumber 
         << endl;
         break;
    case "X";
         cout<< " The Answer is:"<< dfirstnumber << "X" << dsecondnumber 
         << dfirstnumber << "=" << dfirstnumber * dsecondnumber 
         << endl;
         break;
    case "/";
         if (dsecondnumber == 0) {
         cout << " That is an invalid operation!" << endl;
         }else {
         cout<< " The Answer is:"<< dfirstnumber << "/" << dsecondnumber 
         << dfirstnumber << "=" << dfirstnumber / dsecondnumber 
         << endl;
         }
         break;
    default: 
         cout<< " That is an invalid operation" << endl;
         break;
         {
         cout<< " Would you like to start again? (Y or N)" << endl;
         cin>> cDoagain;
    }while (cDoagain == 'Y'  || cDoagain == 'y');
    system ("Pause");
    return 0;
}

Also I thought that I would include the error log so that some one might possible explain what it is that the program is talking about and possible way to fix them.
Error Log
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing  make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c switches.cpp -o switches.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   

switches.cpp:4:20: warning: extra tokens at end of #include directive
switches.cpp: In function `int main()':

switches.cpp:20: error: `dfistnubmer' undeclared (first use this function)
switches.cpp:20: error: (Each undeclared identifier is reported only once for each function it appears in.)

switches.cpp:24: error: no match for 'operator<<' in 'std::cin << "Please enter the second number that you would like to use."'
switches.cpp:28: error: case label `"+"' not within a switch statement
switches.cpp:28: error: expected `:' before ';' token

switches.cpp:33: error: case label `"-"' not within a switch statement
switches.cpp:33: error: expected `:' before ';' token

switches.cpp:38: error: case label `"*"' not within a switch statement
switches.cpp:38: error: expected `:' before ';' token
switches.cpp:43: error: case label `"x"' not within a switch statement
switches.cpp:43: error: expected `:' before ';' token
switches.cpp:48: error: case label `"X"' not within a switch statement
switches.cpp:48: error: expected `:' before ';' token

switches.cpp:53: error: case label `"/"' not within a switch statement
switches.cpp:53: error: expected `:' before ';' token

switches.cpp:62: error: case label not within a switch statement

switches.cpp:71: error: expected `}' at end of input
switches.cpp:71: error: expected `while' at end of input

switches.cpp:71: error: expected `(' at end of input
switches.cpp:71: error: expected primary-expression at end of input
switches.cpp:71: error: expected `)' at end of input
switches.cpp:71: error: expected `;' at end of input
switches.cpp:71: error: expected `}' at end of input

make.exe: *** [switches.o] Error 1

Execution terminated



If you all could assist me in find out how to fix the errors I would greatly appreciate the assistance.

Best
Archiphile
Last edited by archiphile; Apr 15th, 2009 at 1:13 am. Reason: wrapping code
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,810
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: A Curious Thing...

 
0
  #2
Apr 15th, 2009
Anytime you get an "undeclared: first use" error, double-check the spelling. In your case, you have some slight typos:

cin>> dfistnubmer;

instead of:
cin>> dfirstnumber;

You left an 'r' off and transposed "mb":

Fix and recompile. Then you have:

cin<< ("Please enter the second number that you would like to use.") << endl;

Should be cout instead of cin and get rid of the parentheses.

switch (cChar);

Delete the semicolon.

  1. case "+";

Replace the double quotes with single quotes and replace the semicolon with a colon:

  1. case '+':

Do that for all of your case statements.
Last edited by VernonDozier; Apr 15th, 2009 at 1:26 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 440
Reputation: Agni is a jewel in the rough Agni is a jewel in the rough Agni is a jewel in the rough 
Solved Threads: 68
Sponsor
Agni's Avatar
Agni Agni is offline Offline
Posting Pro in Training

Re: A Curious Thing...

 
0
  #3
Apr 15th, 2009
This is a first, a video problem ... what if the video was edited? .. Not a good way to learn programming I'd say ...
thanks
-chandra
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 79
Reputation: MatEpp is an unknown quantity at this point 
Solved Threads: 12
MatEpp MatEpp is offline Offline
Junior Poster in Training

Re: A Curious Thing...

 
0
  #4
Apr 15th, 2009
Remove the semi colon from

  1. #include <iostream>;
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: A Curious Thing...

 
0
  #5
Apr 15th, 2009
In addition to the above posts:
1) The user has no chance to input the second number. Better add cin>>dsecondnumber; after the user is told to input the second number.
2) In your case statements the output is always
cout<< " The Answer is:"<< dfirstnumber << (operator) << dsecondnumber << dfirstnumber << "=" << dfirstnumber (operator) dsecondnumber << endl;
Why do you output the first number again? The output for 5*6 now (with that unnecessary output addition) is "The Answer is:5*65=30".
3) Change this:
default: 
         cout<< " That is an invalid operation" << endl;
         break;
         {
         cout<< " Would you like to start again? (Y or N)" << endl;
         cin>> cDoagain;
to
default: 
         cout<< " That is an invalid operation" << endl;
         break;
         }
         cout<< " Would you like to start again? (Y or N)" << endl;
         cin>> cDoagain;

4)
Just for comfort - you could write this:
  1. case '*':
  2. cout<< " The Answer is:"<< dfirstnumber << "*" << dsecondnumber
  3. << "=" << dfirstnumber * dsecondnumber
  4. << endl;
  5. break;
  6. case 'x':
  7. cout<< " The Answer is:"<< dfirstnumber << "x" << dsecondnumber
  8. << "=" << dfirstnumber * dsecondnumber
  9. << endl;
  10. break;
  11. case 'X':
  12. cout<< " The Answer is:"<< dfirstnumber << "X" << dsecondnumber
  13. << "=" << dfirstnumber * dsecondnumber
  14. << endl;
  15. break;

at bit shorter:
  1. case 'x':
  2. case 'X':
  3. case '*':
  4. cout<< " The Answer is:"<< dfirstnumber << "*" << dsecondnumber
  5. << "=" << dfirstnumber * dsecondnumber
  6. << endl;
  7. break;
Last edited by unbeatable0; Apr 15th, 2009 at 4:41 am.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: archiphile is an unknown quantity at this point 
Solved Threads: 0
archiphile archiphile is offline Offline
Newbie Poster

Re: A Curious Thing...

 
0
  #6
Apr 15th, 2009
Thank you all for the assistance. I will fix and recompile. BTW I am using the video because it is cheap (read Free). Thanks again

Best,

Archiphile
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 90
Reputation: unbeatable0 is an unknown quantity at this point 
Solved Threads: 12
unbeatable0 unbeatable0 is offline Offline
Junior Poster in Training

Re: A Curious Thing...

 
0
  #7
Apr 15th, 2009
There are free-to-read tutorials on the Internet as well.
Two good sites:
http://cprogramming.com
http://cplusplus.com
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 101
Reputation: PirateTUX is an unknown quantity at this point 
Solved Threads: 3
PirateTUX's Avatar
PirateTUX PirateTUX is offline Offline
Junior Poster

Re: A Curious Thing...

 
0
  #8
Apr 15th, 2009
Exactly what I was going to say, unbeatable0. You are far better off learning from some sort of print media than video.

To be completely honest, if you're truly committed to learning how to program, investing in a good solid C++ book shouldn't be out of the question. The lessons will be written down, you can notate a book, there will be practice questions with answers, and the lessons will be complete.

When I was learning Ogre3D, I tried to do it from online tutorials, but in the end, learned there is no substitute for a well written book.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: archiphile is an unknown quantity at this point 
Solved Threads: 0
archiphile archiphile is offline Offline
Newbie Poster

Re: A Curious Thing...

 
0
  #9
Apr 15th, 2009
So I think that I have fixed most of what has been talked about before. I am coming up with one error that I do not understand.
Error is as follows:

switches.cpp(64) : fatal error C1075: end of file found before the left brace '{' 
switches - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If any one could not just tell me how to fix it,but the why behind it would be great. Thank you all for your assistance.

Best,

Archiphile
Last edited by archiphile; Apr 15th, 2009 at 11:49 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 4
Reputation: archiphile is an unknown quantity at this point 
Solved Threads: 0
archiphile archiphile is offline Offline
Newbie Poster

Re: A Curious Thing...

 
0
  #10
Apr 15th, 2009
For all of the people saying that I should get a good text, I am in concurrence with you on that statement. I have to get some cash together so that I can invest. The on line tutorials are a supplement to the texts that I am planning to purchase in the future. Thank you all for you assistance, I really appreciate all of your guidance.


Best,

Archiphile
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC