Computer problems,Computer help
*AX SOFT>>>Programming & Design

C++ help! why a number 1 keeps on popping up in my priming read?


i am putting the 1 in my acummulator....but i don't know...i am just learning...can someone please help me! this is my code:
(by the way, what else do you all see wrong with it?)

#include <iostream>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::setprecision;


int main()
{
//declare variables
double monthSales = 0.0;
int regions = 1;
double totalSales = 0.0;

while (regions <= 4)
{
cout << "Enter region: " << regions;
cin >> monthSales;

totalSales = totalSales + monthSales;

regions = regions + 1;
//end while
}
cout << fixed << setprecision(2);
cout << "Total sales: " << totalSales << endl;
return 0;
} //end of main function

cout << "Enter region: " << regions;

because of that ...

The program is OK ... but there's some changes will make shorter ...

instead of
writing the 4 using::std ....

u can write once : using namespace std;

so, u won't need to write "using::std " else...

and instead of the while loop ... it would be better to use a for loop ... like :

for(regions=1;regions<=4;regions++)
{
// write your code here without the "regions = regions + 1" line ...
}

and instead of "totalSales = totalSales + monthSales;"
you could write "totalSales += monthSales;"

Whats wrong with this? The only thing I'm not sure about is the line that reads:

cout << fixed << setprecision(2);

everything else looks fine.

cout << "Enter region: " << regions;

Are you asking why this is outputting "Enter region: 1"?

Simply, it's because you're outputting the the variable region.

cout << "Enter region:";

That's what you want. If this isn't what you're asking then I see nothing wrong with your program.

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • What's the difference between URL, Direct Link, HTML and IMG???

    url = universal resource location direct link = the direct link to the source html = hyper text transfer protocol img = image

    ...
  • Questions removed?

    Did it have any answers? If it expires, with no answers, a question gets deleted. If more than one person considered to be a "reliable user" reports a question, then it will automatic...

  • What would be the pseudo code for this piece of Visual Basic code that is underneath???

    start function Load if gfGetYellow is false then exit function for li as 1 to the last element of laParkData if the value of the li'th item at position 1 in laparkdata is not equal t...

  • What is a fair salary for an asp.net and C# programmer in north carolina?

    I am not sure about north carolina but I think the pay also depends on the work. Light asp and C# work in this economy you might be able to find someone for around $35k. Managing multiple sites wit...

  • Question for those who use google adsense?

    I have ad sense on 7 different websites. I have been extremely successful with ad sense. I make my living off of the add revenue . The revenue from each site it different. Revenue is base on the a...

  • For a Web design position. What are the advantages and disadvantages of pursuing this type of position?

    First, be clear about where your interests and talents lie. A web designer is someone with artistic ability who designs the site - layout, color scheme, fonts, graphics, etc. Often, web desig...

  • I need a website that factors polynomial equations using javascript so that i can convert it into ti-basic?

    I hope that this helps: ...

  • I need to update my yahoo mail page but how do i get into java script?

    Your Yahoo mail page should update on its own so why do you want to get into javascript? Are you wanting to rewrite the javascript that shows Yahoo mail? Coz if you are you can't, its ru...

  •  

    Categories--Copyright/IP Policy--Contact Webmaster