In my homework, x is unknown. but don't worry, I wont ask for the full code. I just need the part where you change the int into a string/array of char.
For Example, it the entered string is: 0324152397 I want it to get stored in an array like-[0] [3] ...[7]. Secondly the string entered may be of any length that is defined only at run time. So, I also need to calculate string length. How could I do that.
Ok so I'm in a programming 1 class working with c++. I have the following assignment:
Write a C++ program that: asks for and accepts the Percentage earned with as a double (i.e. 75.45) rounds it to an integer (>= .5 rounds up, <.5 rounds down.) prints the original Percentage and the corresponding Grade and Points exactly as shown below. prints an error message for any input that is less than 0 or greater than 100.
For example, if user enters 89.4, the program prints out: Percentage: 89.4% Grade: B Points: 3.00 You must use an if-else statement to do this in your program. Use fixed and precision output manipulators (see Ch. 3) to display the values with the exact precision shown above.
IMPORTANT: Each if statement condition should contain only one comparison! read this again This means code that is similar to this is NOT okay: if (Percentage >= 80.00 && Percentage <90.00) This code is not acceptable because the if statement condition above has two comparisons. (Hint: If you order your if-else chain statements correctly, you will only need one comparison in each.)
I have the program working, but I'm pretty sure I'm not rounding how my professor would like it to. This is my code:
So my issue here is the rounding, and then theres the converting the double percetnage to an integer. In my next assignment I have to write the program with a switch statement.
I'm able to convert an integer to a vector<unsigned char> and back. However, when I try to use a nearly identical function designed for the long long data type, the last byte or two is broken.
Program code:
long long num = 9223372036854775551LL; cout << "Before: " << num << endl; vector<unsigned char> data = getBytes(num); num = getLongLong(data); cout << "After: " << num << endl;
Code for converting between vector<unsigned char> and long long:
Code: vector<unsigned char> getBytes(long long value) { int bytes = sizeof(value); vector<unsigned char> data(bytes); for (int i = 0; i < bytes; i++) data.at(i) = (unsigned char)( value >> ((bytes-i)*8) );
I have been tasked with making a diamond out of asterisks based on a given odd integer input. For some reason the bottom half of my diamond will not print. I'm not sure as to why.
I have a vector which contains vectors containing 7 integers each. I'd like to sort these vectors based on the value of the first integer (int IOT), in ascending order. I know this type of question can be found everywhere, but I'm lost as to why this doesn't compile.
#include <fstream> #include <iostream> #include <vector> #include <string> #include <algorithm> #include <stdio.h> #include <math.h> #include <windows.h> using namespace std; class orders { public: int IOT; // Incoming Order Time
I am working on an assignment about converting an integer number to its 2's complement presentation. The binary representation is consisting of a single linked list.
As we all know, the steps of this converting is to taking the reminder of the absolute value, then flipping the 1 to be 0, and the 0 to be 1 in the binary number. And the last step will be to add 1 to the binary number invers.
I wrote a code that implements every thin correctly. However, when I reached the part of adding 1, the program was hanged.
int Absolute; //the first step is to convert the number to the binry reprezentation Absolute = abs (value);// by take the Absolute value of the negative number, then find the while (Absolute !=0) //the binary reprezentation { int res; res= (Absolute % 2); pushFront (res); Absolute /=2 ;
I am trying to assign the integer value to unsigned char array. But it is not storing the integer values. It prints the ascii values. Here the code snippet
The values which are stored in uc[] is ascii values.I need the integer values to be stored in uc[]. I tried to do it with sprintf. but the output is not as expected. if I print the uc[i] it should diplay the value as 0,1,2....99.
changing a 9 digit integer into a new 9 digit integer through simple mathematical operations. For example, I need to change 123456789 into the new digit 456123789. Sometimes I need to change a 9 digit integer into an 8 digit integer. An example is 789062456 into 62789456. I can ONLY use simple mathematical operations (addition, subtraction, multiplication, division and modulo).
What I want is basically to assign to the *p the pointer of the string so that i could do the following printf(" print string %s",*p); so i dont know how to do that.
I'm having a problem converting part of a string to an integer.I used strtok to seperate my string and I have also a function for atoi but how to apply it to my strtok function.What i need is to change the char *years to an int.Have a look of what I got:
Code: int main() { char sentence[]="trade_#_2009_#_invest_#_DEALING"; char *word=strtok(sentence, "_#_"); char *year=strtok(NULL, "_#_");; // assigning NULL for previousely where it left off char *definition=strtok(NULL,"_#_"); char *synonyms=strtok(NULL,"_#_");
wrote this program to check if a string is an integer. It checks for + or - sign at the front of it, but it spat out some errors.I think I broke it.Here is the code:
Code:
#include<stdio.h> #include<ctype.h> #include<stdlib.h> int getInteger(char*); int main(void) { char str[99]; int x; }
I have been trying to write a function which can convert a number from an unsigned long integer to a readable ASCII character string. this is what I have come up with, but I am receiving some very strange characters in return. Could the problem be that I am telling a char to = an unsigned long int, (cString[i] = product[i])?
void convertToString(unsigned long con) { unsigned long product[10]; char cString[10]; const unsigned long begConvert = 10 ^ 10;
int main () { string integer1; string integer2; cout <<" enter your first number: " << endl; cin >> integer1; cout << endl; cout << integer1 << " is your first number" << endl; }
Now how do I turn the string integer into an array?
I'm just learning and C. Here is a code snippit from a program that will compile. It's function is to validate credit card numbers. I have an error I can't find though. the last print statement shows the conversion in reverse string (as integers). Here is the code:
int main (void) { char cn[17]; char *cardtype; int n0,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12,n13,n14, n15; int s1,s2,s3,s4,s5,s6,s7,s8; int oddsum; int sum; int total; int validate; }