473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

I am making a timer but i have an error blocking the way. Please help me

ok so i am getting an error in this program i did not test it out because of the error ok so the error is
(expected primary-expression before ')' token) that and i am getting two warnings ([Warning] character constant too long for its type) the other warning is the same but for another line. So if any one can fix this problem i will be thank full.


Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4.  
  5. using namespace std;
  6. int main()
  7. {
  8.     int min;
  9.     int sec;
  10.     cout<<"Enter Minutes: ";
  11.     cin>>min;
  12.     cout<<"Enter Seconds: ";
  13.     cin>>sec;
  14.     cout<< "To Start Timer. Press Any Key.";
  15.     getch();
  16.     while(){
  17.             cout<< min <<" : "<< sec<< endl;
  18.  
  19.           Sleep(750);
  20.     switch (min)
  21.     {
  22.            case 'min > 0':--min;
  23.            break;
  24.            case 'min == 0':min = 0;
  25.            break;
  26.            }
  27.            if (min - 1){
  28.                    sec = 59;
  29.                    --sec;
  30.                    }
  31.     if (min == 0 & sec == 0){
  32.             cout<<"Timer is done. Press any key to Exit";
  33.             getch();
  34.             break;
  35.             }
  36.             }
  37.             return 0;
  38.             }
Feb 3 '14 #1

✓ answered by Nepomuk

The error is in the while loop; line 16 which is
Expand|Select|Wrap|Line Numbers
  1. while(){
makes no sense. You have to include the condition for which the loop should be continued; if you want to continue it until you exit with break the condition would simply be true.

7 1136
weaknessforcats
9,208 Expert Mod 8TB
Your while loop cannot be while(). You must supply the condition for exiting the loop. If you want an infinite loop, then code while(1).

Then this:

Expand|Select|Wrap|Line Numbers
  1.   switch (min)
  2.     {
  3.            case 'min > 0':--min;
  4.            break;
  5. etc...
A case is not the same as an if statement. For a case you specify the value of min for the case like 5 or 10 or 0. It must be an integer.

This code:
Expand|Select|Wrap|Line Numbers
  1.  if (min == 0 & sec == 0){
  2.             cout<<"Timer is done. Press any key to Exit";
  3.             getch();
  4. etc...
If you mean min s zero AND sec is zero, then use the && operator and not &.
Feb 3 '14 #2
Nepomuk
3,112 Expert 2GB
The error is in the while loop; line 16 which is
Expand|Select|Wrap|Line Numbers
  1. while(){
makes no sense. You have to include the condition for which the loop should be continued; if you want to continue it until you exit with break the condition would simply be true.
Feb 3 '14 #3
Which line it reported to have warning?
Feb 3 '14 #4
The Warning is on line 22 and 24 so please fix this if you can
Feb 4 '14 #5
Nepomuk
3,112 Expert 2GB
You can't use the switch-case structure like that; the cases have to be concrete values, not conditions. The warnings came because anything in single quotes (' ') is interpreted to be a character and as in C characters can be mapped to integers, the code compiles. However it would probably just use the first character from the expression, so it would check whether min == 'm'. Not what you want.

If you want more flexibility, you'll have to use if-else statements; so what you're trying to do would look something like this:
Expand|Select|Wrap|Line Numbers
  1. if (min > 0) {
  2.     --min;
  3. } else if (min == 0) {
  4.     min = 0;
  5. }
Feb 4 '14 #6
Sorry that I was away. I think Nepomuk has solved the warning.
Feb 13 '14 #7
Yup he did solve the thing
Feb 13 '14 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: TeknoCat | last post by:
Hey everyone, I may be repeating myself here, but if someone sent a reply then I missed it, and I can't get Outlook Express to download any messages more than 2 days old. Anyway, I'm having a...
14
by: tasheeta | last post by:
In my simple program I am getting this error..please help I am trying to find integers where 65537i + 3551j = 1 error: cannot convert `__complex__ int' to `long int' in assignment ...
3
by: N. Graves | last post by:
Hello, I don't understand this error message." Error accessing File. Network Connection may have been lost." I'm not using any network connection for the database. In the VBA editor is goes...
4
by: Chua Wen Ching | last post by:
Thanks Derek... Okay i had another question.. my program runs smoothly for the first minute, after 1 minute... suddenly it breaks and display this error: do you know what is the cause of...
1
by: Franko | last post by:
I get the following error. Please help c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,38): error CS1001: Identifier expected c:\inetpub\wwwroot\WebApplication1\WebForm2.aspx(6,52): error...
8
by: D P | last post by:
Hello everyone, I am new here and I hope I can get the help I need. I will be as descriptive as possible!! I have developed an app using VB.NET that requires making a connection to an access...
6
by: mohtasham1983 | last post by:
Hello everybody, I am trying to make a C++ timer on windows which has following functionality: Once the function is called, timer should start and last for 10 seconds, but in this period of time,...
0
by: smtwtfs007 | last post by:
Any body has any idea about his error please? I got this error at the time of creating crystal report. I tried everything to resolve this error. But I could not. Please help. Exception has...
1
by: charith | last post by:
Hi All, I get this error very frequently syntax error () in frequently calling a servlets and html files also In the response of the makeRequest is this way "body":"","rc":"504" When clicked...
2
by: chumly96 | last post by:
Hi All, I need some help writing a library for a fedora box. What I need to do is intercept timer calls, and cache the results that are within 1ms. eg: first call, get time. Second call, check...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.