4854 Shares

Need help with C++ while program?

Need help with C++ while program? Topic: How to write a while loop program
July 20, 2019 / By Lawrie
Question: An internet service provider has three different subscription packages for its customers: Package A: $9.95 a month, 10 hours of access, additional hours are $2.00 per hour Package B: $14.95 a month, 20 hours of access, additional hours are $1.00 per hour Package C: $19.95 a month, unlimited access Write program that calculates customer's monthly bill. Ask which package customer purchased and hour many hours were used. It should then display total amount due. Input validation: User can only select A, B, or C. Number of horus <= 744 I don't know how to do this.. Please help I've tried it and I don't know how to do the while loop using single characters.. I'm stuck.. #include using namespace std; int main() { char A; char input; int i = 1; cout << "Select a package: " << endl; cout << "Package\t\tCost\t\tHours Provided\t\tExtra Hours" << endl; cout << "A\t\t$9.95\t\t10\t\t\t$2.00 per hour" << endl; cout << "B\t\t$14.95\t\t20\t\t\t$1.00 per hour" << endl; cout << "C\t\t$19.95\t\tUnlimited\t\tUnlimited" << endl; cout << "Enter A, B, or C for the package you have purchased: " << endl; cin >> input; if(input = A) { cout << "How many hours were used? " << endl; } return 0; } Could you just set me in the right direction using the single letter characters? I'm lost.. and I know if() shouldn't be used there where i have it
Best Answer

Best Answers: Need help with C++ while program?

Jachin Jachin | 6 days ago
okay, here we go: While { you're getting us to do your homework for you; you won't learn a thing; } return 0;
👍 220 | 👎 6
Did you like the answer? Need help with C++ while program? Share with your friends

We found more questions related to the topic: How to write a while loop program


Jachin Originally Answered: Need help with C++ while program?
okay, here we go: While { you're getting us to do your homework for you; you won't learn a thing; } return 0;

Jachin Originally Answered: Can someone help me get started on this Java program?
EDIT: http://pastebin.com/f13483554 ======================================... Here's the code. import java.io.*; public class OddEven { public static void main(String args[])throws IOException { BufferedReader in=new BufferedReader(new InputStreamReader(System.in)); int n,i,oddSum=0,evenSum=0; char a='\b'; System.out.println("Enter the number: "); n=Integer.parseInt(in.readLine()); for(i=1;i<=n;i++){ if(i%2==0){ evenSum+=i; } else{ oddSum+=i; } } System.out.print("Sum of even integers = "); for(i=1;i<=n;i++){ if(i%2==0) System.out.print(i+" + "); } System.out.print(a); System.out.print(a); System.out.print("="+evenSum); System.out.println(); System.out.print("Sum of odd integers = "); for(i=1;i<=n;i++){ if(i%2!=0) System.out.print(i+" + "); } System.out.print(a); System.out.print(a); System.out.print("="+oddSum); } } Here's the code, in case some part of the code gets truncated on Yahoo Answers.http://pastebin.com/f78e46c5a Hope this helps. Let me know if you have any queries. Have fun :)
Jachin Originally Answered: Can someone help me get started on this Java program?
int evens = 0; int odds = 0; int input = 15; for ( int i = 1; i <= input; i++ ) { ..... if ( i % 2 == 0 ) { .......... evens++; ..... } else { .......... odds++; ..... } } System.out.println( "Evens: " + evens + ", Odds: " + odds );

If you have your own answer to the question how to write a while loop program, then you can write your own version, using the form below for an extended answer.