•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,838 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,583 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 186 | Replies: 4
![]() |
| |
•
•
Join Date: May 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
Hi all I am learning C++ , but am still pretty new to it I have one problem I am writing a program to simply input a mark and then it gives the corresponding symbol and according to the symbol if its anything above an E it displays you pass and if not it displays you dont , I have had no problem writing this :
[ // Symbol issuing program as per mark out of 100.
#include <iostream>
using namespace std;
int symbol(int mark)
{
if (mark >= 0 && mark <= 39)
return 70;
if (mark >= 40 && mark <= 49)
return 69;
if (mark >= 50 && mark <= 59)
return 68;
if (mark >= 60 && mark <= 69)
return 67;
if (mark >= 70 && mark <= 79)
return 66;
if (mark >= 80 && mark <= 100)
return 65;
}
bool passOrNot (char symb)
{
char A, B, C, D, E , F;
if (symb <= 68 )
return 1;
}
int main()
{
int mark;
char symb;
cout << "Enter marks out of 100 followed by -10 to end inputs and display the results: ";
cin >> mark;
symb = symbol(mark);
cout << "Symbol corresponding to " << mark << " is " << symb;
if (passOrNot (symb))
cout << " You Pass Congratulations!"<< endl;
else
cout << " Unfortunately you fail" << endl;
return 0;
}
]
Except now I want to impliment a While loop into it so that I can enter a number of marks followed by -10 (or any defined number below 0) to end my inputs and display the results of each mark , yet everything I try doesnt work , it either gets stuck in a loop or simply stops on my 1st number entered , Please could somebody help me out here.
[ // Symbol issuing program as per mark out of 100.
#include <iostream>
using namespace std;
int symbol(int mark)
{
if (mark >= 0 && mark <= 39)
return 70;
if (mark >= 40 && mark <= 49)
return 69;
if (mark >= 50 && mark <= 59)
return 68;
if (mark >= 60 && mark <= 69)
return 67;
if (mark >= 70 && mark <= 79)
return 66;
if (mark >= 80 && mark <= 100)
return 65;
}
bool passOrNot (char symb)
{
char A, B, C, D, E , F;
if (symb <= 68 )
return 1;
}
int main()
{
int mark;
char symb;
cout << "Enter marks out of 100 followed by -10 to end inputs and display the results: ";
cin >> mark;
symb = symbol(mark);
cout << "Symbol corresponding to " << mark << " is " << symb;
if (passOrNot (symb))
cout << " You Pass Congratulations!"<< endl;
else
cout << " Unfortunately you fail" << endl;
return 0;
}
]
Except now I want to impliment a While loop into it so that I can enter a number of marks followed by -10 (or any defined number below 0) to end my inputs and display the results of each mark , yet everything I try doesnt work , it either gets stuck in a loop or simply stops on my 1st number entered , Please could somebody help me out here.
•
•
Join Date: May 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
Basically I have this but entering -10 doesnt end it???
[// Symbol issuing program as per mark out of 100.
#include <iostream>
using namespace std;
int symbol(int mark)
{
if (mark >= 0 && mark <= 39)
return 70;
if (mark >= 40 && mark <= 49)
return 69;
if (mark >= 50 && mark <= 59)
return 68;
if (mark >= 60 && mark <= 69)
return 67;
if (mark >= 70 && mark <= 79)
return 66;
if (mark >= 80 && mark <= 100)
return 65;
}
bool passOrNot (char symb)
{
char A, B, C, D, E , F;
if (symb <= 68 )
return 1;
}
int main()
{
int mark;
char symb;
mark = 1;
while (mark != -10, mark++){
cout << "Enter mark out of 100 , enter -10 to end: ";
cin >> mark;
symb = symbol(mark);
cout << "Symbol corresponding to " << mark << " is " << symb;
if (passOrNot (symb))
cout << " You Pass Congratulations!"<< endl;
else
cout << " Unfortunately you fail" << endl;
}
return 0;
}
]
[// Symbol issuing program as per mark out of 100.
#include <iostream>
using namespace std;
int symbol(int mark)
{
if (mark >= 0 && mark <= 39)
return 70;
if (mark >= 40 && mark <= 49)
return 69;
if (mark >= 50 && mark <= 59)
return 68;
if (mark >= 60 && mark <= 69)
return 67;
if (mark >= 70 && mark <= 79)
return 66;
if (mark >= 80 && mark <= 100)
return 65;
}
bool passOrNot (char symb)
{
char A, B, C, D, E , F;
if (symb <= 68 )
return 1;
}
int main()
{
int mark;
char symb;
mark = 1;
while (mark != -10, mark++){
cout << "Enter mark out of 100 , enter -10 to end: ";
cin >> mark;
symb = symbol(mark);
cout << "Symbol corresponding to " << mark << " is " << symb;
if (passOrNot (symb))
cout << " You Pass Congratulations!"<< endl;
else
cout << " Unfortunately you fail" << endl;
}
return 0;
}
]
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,598
Reputation:
Rep Power: 8
Solved Threads: 163
You have an error here:
Change it to:
And the program will end when -10 is entered
The next time you post code, please use code tags
while (mark != -10, mark++)
Change it to:
while (mark != -10)
And the program will end when -10 is entered
The next time you post code, please use code tags
Last edited by niek_e : May 16th, 2008 at 7:32 am.
do NOT pm me for help, it makes me angry. You wouldn't like me when I'm angry...
•
•
Join Date: Oct 2006
Location: the Netherlands
Posts: 1,598
Reputation:
Rep Power: 8
Solved Threads: 163
You can send Private Messages (PM) to people by clicking on their name and select 'send Private Message'
But I got a lot of PM's of people begging me for source-code and it irritated the hell out of me.
So I added a signature PM's asking for help will be ignored.. so everyone can see that PMing me won't help them.
The signature will display in every message I post.
To add a signature of your own, goto 'control panel' (top of the screen) and click 'edit signature'
But I got a lot of PM's of people begging me for source-code and it irritated the hell out of me.
So I added a signature PM's asking for help will be ignored.. so everyone can see that PMing me won't help them.
The signature will display in every message I post.
To add a signature of your own, goto 'control panel' (top of the screen) and click 'edit signature'
do NOT pm me for help, it makes me angry. You wouldn't like me when I'm angry...
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Need Advice on for loops with vowels (Java)
- Loops (C++)
- Need some help with my do-while and while loops (Java)
- Help with loops (Java)
- Program Help Using For Nested Loops (C++)
- merged:nesting loops (C++)
- help for program involving switch loops and file (C++)
Other Threads in the C++ Forum
- Previous Thread: CreateFile() Serial Communication with USB device
- Next Thread: checkking if user types in a number



Hybrid Mode