|
-
August 14th, 2005, 05:21 AM
#1
Make program loop untill null value is passed.
Hi,
i've had to write this program below to take input in the form of "ONE-HUNDRED" and output "100", only i don't want it to exit straight away. I want it to keep taking inputs untill a null value is passed.
I tried using a do while loop but it doesn't take in inputs after the first one and keeps printing the current output to the screen.
Here is what i have so far.
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char number[80];
char *str = NULL;
int output = 0;
cout << "Student ID 4095983" << endl;
cin.get( number, 79 );
str = strtok( number, " -" );
while ( str != NULL ) {
if( strcmp(str, "ZERO") == 0) {
output += 0;
}
else if( strcmp(str, "ONE") == 0) {
output += 1;
}
else if( strcmp(str, "TWO") == 0) {
output += 2;
}
else if( strcmp(str, "THREE") == 0) {
output += 3;
}
else if( strcmp(str, "FOUR") == 0) {
output += 4;
}
else if( strcmp(str, "FIVE") == 0) {
output += 5;
}
else if( strcmp(str, "SIX") == 0) {
output += 6;
}
else if( strcmp(str, "SEVEN") == 0) {
output += 7;
}
else if( strcmp(str, "EIGHT") == 0) {
output += 8;
}
else if( strcmp(str, "NINE") == 0) {
output += 9;
}
else if( strcmp(str, "TEN") == 0) {
output += 10;
}
else if( strcmp(str, "ELEVEN") == 0) {
output += 11;
}
else if( strcmp(str, "TWELVE") == 0) {
output += 12;
}
else if( strcmp(str, "THIRTEEN") == 0) {
output += 13;
}
else if( strcmp(str, "FOURTEEN") == 0) {
output += 14;
}
else if( strcmp(str, "FIFTEEN") == 0) {
output += 15;
}
else if( strcmp(str, "SIXTEEN") == 0) {
output += 16;
}
else if( strcmp(str, "SEVENTEEN") == 0) {
output += 17;
}
else if( strcmp(str, "EIGHTEEN") == 0) {
output += 18;
}
else if( strcmp(str, "NINETEEN") == 0) {
output += 19;
}
else if( strcmp(str, "TWENTY") == 0) {
output += 20;
}
else if( strcmp(str, "THIRTY") == 0) {
output += 30;
}
else if( strcmp(str, "FORTY") == 0) {
output += 40;
}
else if( strcmp(str, "FIFTY") == 0) {
output += 50;
}
else if( strcmp(str, "SIXTY") == 0) {
output += 60;
}
else if( strcmp(str, "SEVENTY") == 0) {
output += 70;
}
else if( strcmp(str, "EIGHTY") == 0) {
output += 80;
}
else if( strcmp(str, "NINETY") == 0) {
output += 90;
}
else if( strcmp(str, "HUNDRED") == 0) {
output *= 100;
}
else if( strcmp(str, "THOUSAND") == 0) {
output *= 1000;
}
else if( strcmp(str, "MILLION") == 0) {
output *= 1000000;
}
str = strtok( NULL, " -" );
}
cout << "Conversion to integer is: " << output << endl;
}
Any help appreciated,
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|