![]() |
Ugh comments suck. Can I do it tomorrow?
|
Ok its already 1 day, times up
|
Well, I don't feel like doin it now. Also, I'm not your bitch, so... if I decide to do it later, I might.
|
puh-lease can you do it now?
|
due tomorrow help with comments!!!
|
Can you add some comments and edit these to fit the criteria? kthx
#include<stdio.h> #include <iostream.h> int main() //Main function { int i; //Define variables int previous = 0; int num; int total = 0; int flag = 0; int key = 0; int repeat = 1; char roman[50]; //defines roman char for input char roman2[50]; //defines roman char for output char pchar = 'z'; cout << "Enter the Roman numeral(in caps!!): "; //prompt for user input cin >>roman; for (i = 0; i < 50; i++) //count what the input value range is { if (roman[i] == 'M') //assigns 1000 to input M num = 1000; else if (roman[i] == 'D') //assigns 500 to input D num = 500; else if (roman[i] == 'C') //assigns 100 to input C num = 100; else if (roman[i] == 'L') //assigns 50 to input L num = 50; else if (roman[i] == 'X') //assigns 10 to input X num = 10; else if (roman[i] == 'V') //assigns 5 to input V num = 5; else if (roman[i] == 'I') //assigns 1 to input I num = 1; else if (roman[i] == '\0') //if input is 0 flag=1 for error flag = 1; /****************************Start Calculation for order of input******************/ /* If input has a value next to it, it checks to see if its more or less than first */ /* If it has less value than the one to the right, substract, if it has higher value add */ if (num == previous) repeat = repeat + 1; else repeat = 1; if (repeat == 4 && num == 1) { flag = 1; } if (repeat == 2 && num == 5) { flag = 1; } if (repeat == 4 && num == 10) { flag = 1; } if (repeat == 2 && num == 50) { flag = 1; } if (repeat == 4 && num == 100) { flag = 1; } if (repeat == 2 && num == 500) { flag = 1; } if (flag == 0) { if (num > previous) { if (key == 1) { i = 50; } total = (total - (2 * previous)) + num; key = 1; } else total += num; previous = num; num = 0; } else { i = 50; } } cout<<total << endl; //Output the calculated number given that roman characters are calculated right /*******************************START DOUBLING****************************************/ total = total * 2; //doubles the number you got from convertion repeat = 1; for (i = 0; i < 50; i++) { //Given then total in int , assign character to each int value if (total >= 1) roman2[i] = 'I'; if (total >= 5) roman2[i] = 'V'; if (total >= 10) roman2[i] = 'X'; if (total >= 50) roman2[i] = 'L'; if (total >= 100) roman2[i] = 'C'; if (total >= 500) roman2[i] = 'D'; if (total >= 1000) roman2[i] = 'M'; if (total == 0) roman2[i] = '\0'; if (roman2[i] == pchar) repeat = repeat + 1; else repeat = 1; if (repeat == 4 && roman2[i] == 'I') { roman2[i - 2] = 'V'; roman2[i - 1] = '\0'; } if (roman2[i] == 'M') // After getting the range value calculate exact value by substracting the value character to the left total -= 1000; //and assign character to integer value , convertion. else if (roman2[i] == 'D') total -= 500; else if (roman2[i] == 'C') total -= 100; else if (roman2[i] == 'L') total -= 50; else if (roman2[i] == 'X') total -= 10; else if (roman2[i] == 'V') total -= 5; else if (roman2[i] == 'I') total -= 1; else if (roman2[i] == '\0') i = 50; pchar = roman2[i]; } cout<<roman2; //outputs the double value in roman characters return(0); } |
You could just do it yourself, you know. Ask someone from your class. And if you can't find anyone in your class who can do it, you can hope to be graded on a curve.
|
Don't know what all you want done... How's this?
#include<stdio.h> #include <iostream.h> int main() //Main function { int i; //Define variables int previous = 0; int num; int total = 0; int flag = 0; int key = 0; int repeat = 1; char roman[50]; //defines roman char for input char roman2[50]; //defines roman char for output char pchar = 'z'; cout << "Enter the Roman numeral(in caps!!): "; //prompt for user input cin >>roman; for (i = 0; i < 50; i++) //count what the input value range is { if (roman[i] == 'M') //assigns 1000 to input M num = 1000; else if (roman[i] == 'D') //assigns 500 to input D num = 500; else if (roman[i] == 'C') //assigns 100 to input C num = 100; else if (roman[i] == 'L') //assigns 50 to input L num = 50; else if (roman[i] == 'X') //assigns 10 to input X num = 10; else if (roman[i] == 'V') //assigns 5 to input V num = 5; else if (roman[i] == 'I') //assigns 1 to input I num = 1; else if (roman[i] == '\0') //this is the end of input /****************************Start Calculation for order of input******************/ /* If input has a value next to it, it checks to see if its more or less than first */ /* If it has less value than the one to the right, substract, if it has higher value add */ if (num == previous) repeat = repeat + 1; else repeat = 1; if (repeat == 4 && num == 1) { flag = 1; } if (repeat == 2 && num == 5) { flag = 1; } if (repeat == 4 && num == 10) { flag = 1; } if (repeat == 2 && num == 50) { flag = 1; } if (repeat == 4 && num == 100) { flag = 1; } if (repeat == 2 && num == 500) { flag = 1; } if (flag == 0) { if (num > previous) { if (key == 1) { i = 50; } total = (total - (2 * previous)) + num; key = 1; } else total += num; previous = num; num = 0; } else { i = 50; } } cout<<total << endl; //Output the calculated number given that roman characters are calculated right /*******************************START DOUBLING****************************************/ total = total * 2; //doubles the number you got from convertion repeat = 1; for (i = 0; i < 50; i++) { //Given then total in int , assign character to each int value if (total >= 1) roman2[i] = 'I'; if (total >= 5) roman2[i] = 'V'; if (total >= 10) roman2[i] = 'X'; if (total >= 50) roman2[i] = 'L'; if (total >= 100) roman2[i] = 'C'; if (total >= 500) roman2[i] = 'D'; if (total >= 1000) roman2[i] = 'M'; if (total == 0) roman2[i] = '\0'; if (roman2[i] == pchar) repeat = repeat + 1; else repeat = 1; if (repeat == 4 && roman2[i] == 'I') //I has been repeated too many times { roman2[i - 2] = 'V'; roman2[i - 1] = '\0'; } if (roman2[i] == 'M') // After getting the range value calculate exact value by substracting the value character to the left total -= 1000; //and assign character to integer value , convertion. else if (roman2[i] == 'D') total -= 500; else if (roman2[i] == 'C') total -= 100; else if (roman2[i] == 'L') total -= 50; else if (roman2[i] == 'X') total -= 10; else if (roman2[i] == 'V') total -= 5; else if (roman2[i] == 'I') total -= 1; else if (roman2[i] == '\0') i = 50; pchar = roman2[i]; } cout<<roman2; //outputs the double value in roman characters return(0); } |
All times are GMT -6. The time now is 08:28 AM. |
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.